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