summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gdc.test/runnable/nogc.d
blob: 8214e96e32a1f062fe31abe0bafa30c4c7995790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

extern(C) int printf(const char*, ...);

/***********************/

@nogc int test1()
{
    return 3;
}

/***********************/
// 3032

void test3032() @nogc
{
    scope o1 = new Object();        // on stack
    scope o2 = new class Object {}; // on stack

    int n = 1;
    scope fp = (){ n = 10; };       // no closure
    fp();
    assert(n == 10);
}

/***********************/
// 12642

__gshared int[1] data12642;

int[1] foo12642() @nogc
{
    int x;
    return [x];
}

void test12642() @nogc
{
    int x;
    data12642 = [x];
    int[1] data2;
    data2 = [x];

    data2 = foo12642();
}

/***********************/
// 12936

void test12936() @nogc
{
    foreach (int[1] a; [[1]])
    {
        assert(a == [1]);
    }
    foreach (i, int[1] a; [[1], [2]])
    {
             if (i == 0) assert(a == [1]);
        else if (i == 1) assert(a == [2]);
        else             assert(0);
    }
}

/***********************/

int main()
{
    test1();
    test3032();
    test12642();
    test12936();

    printf("Success\n");
    return 0;
}