Debian Codegraph @

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

raw
1 /*
2 https://issues.dlang.org/show_bug.cgi?id=21693
3
4 RUN_OUTPUT:
5 ---
6 CppA:
7 1: CppA.~this
8 CppB:
9 2: CppB.~this
10 2: CppA.~this
11 CppC:
12 3: CppC.~this
13 3: CppB.~this
14 3: CppA.~this
15 CppC:
16 4: CppC.~this
17 4: CppB.~this
18 4: CppA.~this
19 CppNoDestruct:
20 DA:
21 1: DA.~this
22 DB:
23 2: DB.~this
24 2: DA.~this
25 DC:
26 3: DC.~this
27 3: DB.~this
28 3: DA.~this
29 DC:
30 4: DC.~this
31 4: DB.~this
32 4: DA.~this
33 ---
34 */
35
36 extern (C) int printf(scope const char*, ...);
37
38 extern (C++) class CppA
39 {
40 int num;
41 this(int num) scope
42 {
43 this.num = num;
44 }
45
46 ~this() scope
47 {
48 printf("%d: CppA.~this\n", num);
49 }
50 }
51
52 extern (C++) class CppB : CppA
53 {
54 this(int num) scope
55 {
56 super(num);
57 }
58
59 ~this() scope
60 {
61 printf("%d: CppB.~this\n", num);
62 }
63 }
64
65 extern (C++) class CppC : CppB
66 {
67 this(int num) scope
68 {
69 super(num);
70 }
71
72 ~this() scope
73 {
74 printf("%d: CppC.~this\n", num);
75 }
76 }
77
78 extern (D) class DA
79 {
80 int num;
81 this(int num) scope
82 {
83 this.num = num;
84 }
85
86 ~this() scope
87 {
88 printf("%d: DA.~this\n", num);
89 }
90 }
91
92 extern (D) class DB : DA
93 {
94 this(int num) scope
95 {
96 super(num);
97 }
98
99 ~this() scope
100 {
101 printf("%d: DB.~this\n", num);
102 }
103 }
104
105 extern (D) class DC : DB
106 {
107 this(int num) scope
108 {
109 super(num);
110 }
111
112 ~this() scope
113 {
114 printf("%d: DC.~this\n", num);
115 }
116 }
117
118 extern (C++) class CppNoDestruct
119 {
120 int num;
121 this(int num) scope
122 {
123 this.num = num;
124 }
125 }
126
127 void main()
128 {
129 printf("CppA:\n"); { scope a = new CppA(1); }
130 printf("CppB:\n"); { scope CppA b = new CppB(2); }
131 printf("CppC:\n"); { scope CppA c = new CppC(3); }
132 printf("CppC:\n"); { scope CppB c2 = new CppC(4); }
133
134 printf("CppNoDestruct:\n");
135 {
136 scope const nd = new CppNoDestruct(1);
137 }
138
139 printf("DA:\n"); { scope a = new DA(1); }
140 printf("DB:\n"); { scope DA b = new DB(2); }
141 printf("DC:\n"); { scope DA c = new DC(3); }
142 printf("DC:\n"); { scope DB c2 = new DC(4); }
143 }