Debian Codegraph @

gcc/testsuite/gdc.test/runnable/auto1.d

raw
1 /*
2 RUN_OUTPUT:
3 ---
4 Foo.~this()
5 Foo.~this()
6 Foo.~this()
7 Foo.~this()
8 A2.this()
9 Hello world.
10 A2.~this()
11 Success
12 ---
13 */
14
15 import core.stdc.stdio;
16
17 /******************************************/
18
19 class Foo
20 {
21 static int x;
22
23 ~this()
24 {
25 printf("Foo.~this()\n");
26 x++;
27 }
28 }
29
30 int test1x()
31 {
32 scope Foo f = new Foo();
33 return 6;
34 }
35
36
37 void test1()
38 {
39 {
40 scope Foo f = new Foo();
41 }
42 int c;
43
44 assert(Foo.x == 1);
45 c = test1x();
46 assert(c == 6);
47 assert(Foo.x == 2);
48
49 if (c != 6)
50 scope Foo h = new Foo();
51 assert(Foo.x == 2);
52
53 if (c == 6)
54 scope Foo j = new Foo();
55 assert(Foo.x == 3);
56
57 {
58 scope Foo g = null, k = new Foo();
59 assert(Foo.x == 3);
60 }
61 assert(Foo.x == 4);
62 }
63
64 /******************************************/
65
66 int ax;
67
68 class A2
69 {
70 this() scope
71 {
72 printf("A2.this()\n");
73 ax += 1;
74 }
75
76 ~this() scope
77 {
78 printf("A2.~this()\n");
79 ax += 1000;
80 }
81 };
82
83
84 void test2()
85 {
86 {
87 scope A2 a = new A2();
88 printf("Hello world.\n");
89 }
90 assert(ax == 1001);
91 }
92
93
94
95 /******************************************/
96
97 int status3;
98
99 class Parent3
100 {
101 }
102
103 class Child3 : Parent3
104 {
105 this() scope {
106 assert(status3==0);
107 status3=1;
108 }
109
110 ~this() scope {
111 assert(status3==1);
112 status3=2;
113 }
114 }
115
116 void foo3()
117 {
118 scope Parent3 o = new Child3();
119 assert(status3==1);
120 }
121
122 void test3()
123 {
124 foo3();
125 assert(status3==2);
126 }
127
128 /******************************************/
129
130 int main()
131 {
132 test1();
133 test2();
134 test3();
135
136 printf("Success\n");
137 return 0;
138 }