]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gdc.test/runnable/nogc.d
Add D front-end, libphobos library, and D2 testsuite.
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / runnable / nogc.d
1
2 extern(C) int printf(const char*, ...);
3
4 /***********************/
5
6 @nogc int test1()
7 {
8 return 3;
9 }
10
11 /***********************/
12 // 3032
13
14 void test3032() @nogc
15 {
16 scope o1 = new Object(); // on stack
17 scope o2 = new class Object {}; // on stack
18
19 int n = 1;
20 scope fp = (){ n = 10; }; // no closure
21 fp();
22 assert(n == 10);
23 }
24
25 /***********************/
26 // 12642
27
28 __gshared int[1] data12642;
29
30 int[1] foo12642() @nogc
31 {
32 int x;
33 return [x];
34 }
35
36 void test12642() @nogc
37 {
38 int x;
39 data12642 = [x];
40 int[1] data2;
41 data2 = [x];
42
43 data2 = foo12642();
44 }
45
46 /***********************/
47 // 12936
48
49 void test12936() @nogc
50 {
51 foreach (int[1] a; [[1]])
52 {
53 assert(a == [1]);
54 }
55 foreach (i, int[1] a; [[1], [2]])
56 {
57 if (i == 0) assert(a == [1]);
58 else if (i == 1) assert(a == [2]);
59 else assert(0);
60 }
61 }
62
63 /***********************/
64
65 int main()
66 {
67 test1();
68 test3032();
69 test12642();
70 test12936();
71
72 printf("Success\n");
73 return 0;
74 }