1 // PERMUTE_ARGS: 2 3 struct Field 4 { thisField5 this(this) @safe @nogc pure nothrow {} 6 } 7 8 struct Counter 9 { 10 static size_t cnt; this(this)11 this(this) @safe @nogc nothrow { ++cnt; } 12 } 13 14 struct Foo 15 { thisFoo16 this(this) @safe @nogc pure nothrow {} 17 Field field; 18 } 19 test1()20void test1() @safe @nogc pure nothrow 21 { 22 Foo foo; 23 foo.__xpostblit(); 24 } 25 26 static assert(__traits(hasMember, Foo, "__xpostblit")); 27 28 // 29 30 struct FieldPostblit 31 { 32 Counter counter; 33 } 34 35 struct AggrPostblit 36 { 37 static size_t cnt; this(this)38 this(this) @safe @nogc nothrow { ++cnt; } 39 } 40 41 struct MixedPostblit 42 { 43 static size_t cnt; 44 Counter counter; thisMixedPostblit45 this(this) @safe @nogc nothrow { ++cnt; } 46 } 47 48 struct SNoPostblit {} 49 class CNoPostblit {} 50 51 static assert(!__traits(hasMember, SNoPostblit, "__xpostblit")); 52 static assert(!__traits(hasMember, CNoPostblit, "__xpostblit")); 53 test2()54void test2() @safe @nogc nothrow 55 { 56 FieldPostblit a; 57 assert(Counter.cnt == 0); 58 a.__xpostblit(); 59 assert(Counter.cnt == 1); 60 AggrPostblit b; 61 assert(AggrPostblit.cnt == 0); 62 b.__xpostblit(); 63 assert(AggrPostblit.cnt == 1); 64 Counter.cnt = 0; 65 MixedPostblit c; 66 assert(MixedPostblit.cnt == 0); 67 assert(Counter.cnt == 0); 68 c.__xpostblit(); 69 assert(MixedPostblit.cnt == 1); 70 assert(Counter.cnt == 1); 71 } 72 main()73void main() 74 { 75 test1(); 76 test2(); 77 } 78