| 1 |
// PERMUTE_ARGS: |
| 2 |
|
| 3 |
struct Field |
| 4 |
{ |
| 5 |
~this() @safe @nogc pure nothrow {} |
| 6 |
} |
| 7 |
|
| 8 |
struct Counter |
| 9 |
{ |
| 10 |
static size_t cnt; |
| 11 |
~this() @safe @nogc nothrow { ++cnt; } |
| 12 |
} |
| 13 |
|
| 14 |
struct Foo |
| 15 |
{ |
| 16 |
~this() @safe @nogc pure nothrow {} |
| 17 |
Field field; |
| 18 |
} |
| 19 |
|
| 20 |
class Bar |
| 21 |
{ |
| 22 |
~this() @safe @nogc pure nothrow {} |
| 23 |
Field field; |
| 24 |
} |
| 25 |
|
| 26 |
void test1() @nogc pure nothrow |
| 27 |
{ |
| 28 |
Foo foo; |
| 29 |
foo.__xdtor(); |
| 30 |
scope bar = new Bar(); |
| 31 |
bar.__xdtor(); |
| 32 |
} |
| 33 |
|
| 34 |
static assert(__traits(hasMember, Foo, "__xdtor")); |
| 35 |
static assert(__traits(hasMember, Bar, "__xdtor")); |
| 36 |
|
| 37 |
// |
| 38 |
|
| 39 |
struct FieldDtor |
| 40 |
{ |
| 41 |
Counter counter; |
| 42 |
} |
| 43 |
|
| 44 |
struct AggrDtor |
| 45 |
{ |
| 46 |
static size_t cnt; |
| 47 |
~this() @safe @nogc nothrow { ++cnt; } |
| 48 |
} |
| 49 |
|
| 50 |
struct MixedDtor |
| 51 |
{ |
| 52 |
static size_t cnt; |
| 53 |
Counter counter; |
| 54 |
~this() @safe @nogc nothrow { ++cnt; } |
| 55 |
} |
| 56 |
|
| 57 |
struct SNoDtor {} |
| 58 |
class CNoDtor {} |
| 59 |
|
| 60 |
static assert(!__traits(hasMember, SNoDtor, "__xdtor")); |
| 61 |
static assert(!__traits(hasMember, CNoDtor, "__xdtor")); |
| 62 |
|
| 63 |
void test2() @safe @nogc nothrow |
| 64 |
{ |
| 65 |
FieldDtor a; |
| 66 |
assert(Counter.cnt == 0); |
| 67 |
a.__xdtor(); |
| 68 |
assert(Counter.cnt == 1); |
| 69 |
AggrDtor b; |
| 70 |
assert(AggrDtor.cnt == 0); |
| 71 |
b.__xdtor(); |
| 72 |
assert(AggrDtor.cnt == 1); |
| 73 |
Counter.cnt = 0; |
| 74 |
MixedDtor c; |
| 75 |
assert(MixedDtor.cnt == 0); |
| 76 |
assert(Counter.cnt == 0); |
| 77 |
c.__xdtor(); |
| 78 |
assert(MixedDtor.cnt == 1); |
| 79 |
assert(Counter.cnt == 1); |
| 80 |
} |
| 81 |
|
| 82 |
struct Bar17257(E) |
| 83 |
{ |
| 84 |
~this() @safe @nogc nothrow |
| 85 |
{ |
| 86 |
assert(__traits(hasMember, E, "__xdtor")); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
struct Foo17257A |
| 91 |
{ |
| 92 |
Bar17257!Foo17257A foo; |
| 93 |
~this() @safe @nogc nothrow {} |
| 94 |
} |
| 95 |
|
| 96 |
struct Foo17257B |
| 97 |
{ |
| 98 |
Bar17257!Foo17257B foo; |
| 99 |
} |
| 100 |
|
| 101 |
void test3() @safe @nogc nothrow |
| 102 |
{ |
| 103 |
Foo17257A foo17257A; |
| 104 |
Foo17257B foo17257B; |
| 105 |
} |
| 106 |
|
| 107 |
void main() |
| 108 |
{ |
| 109 |
test1(); |
| 110 |
test2(); |
| 111 |
test3(); |
| 112 |
} |