1 /** Test how destruction of scoped classes is handled.
2  *
3  * See_Also:
4  */
5 module scoped_class_dtor;
6 
7 bool g_dtor_called = false;
8 
9 class C
10 {
11 @safe nothrow @nogc:
12     this(int x) { this.x = x; }
13     ~this() { g_dtor_called = true; }
14     int x;
15     // class fields cannot be scope so this fails: `scope D d = new D(3);`
16 }
17 
18 class D
19 {
20 @safe nothrow @nogc:
21     this(float x) { this.x = x; }
22     float x;
23 }
24 
25 void scopedC() @safe nothrow
26 {
27     scope x = new C(42);
28 }
29 
30 unittest
31 {
32     import core.memory : GC;
33     GC.disable();
34     scopedC();
35     assert(g_dtor_called);
36     GC.enable();
37 }