Debian Codegraph @

gcc/testsuite/gdc.test/runnable_cxx/test24292.d

raw
1 // EXTRA_CPP_SOURCES: test24292.cpp
2
3 extern(C++) struct List(T)
4 {
5 // Any of the following static ifs can trigger the problem.
6 static if (T.sizeof > 4) {}
7 static if (__traits(isZeroInit, T)) {}
8 static if (__traits(isPOD, T)) {}
9
10 T* begin;
11 }
12
13 extern(C++) struct StructWithDestructor
14 {
15 ~this();
16
17 alias L = List!StructWithDestructor;
18 int i;
19 }
20
21 extern(C++) struct StructWithCopyCtor
22 {
23 this(ref const(StructWithCopyCtor));
24
25 alias L = List!StructWithCopyCtor;
26 int i;
27 }
28
29 extern(D) struct StructWithPostblit
30 {
31 this(this) {}
32
33 alias L = List!StructWithPostblit;
34 int i;
35 }
36
37 static assert(!__traits(isPOD, StructWithDestructor));
38 static assert(!__traits(isPOD, StructWithCopyCtor));
39 static assert(!__traits(isPOD, StructWithPostblit));
40
41 extern(C++) StructWithDestructor getStructWithDestructor();
42 extern(C++) StructWithCopyCtor getStructWithCopyCtor();
43
44 void main()
45 {
46 StructWithDestructor structWithDestructor = getStructWithDestructor();
47 assert(structWithDestructor.i == 12345);
48 StructWithCopyCtor structWithCopyCtor = getStructWithCopyCtor();
49 assert(structWithCopyCtor.i == 54321);
50 }