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