| 1 |
/* |
| 2 |
Informative error messages if the compiler inserted an optional destructor call into the constructor. |
| 3 |
|
| 4 |
REQUIRED_ARGS: -preview=dtorfields |
| 5 |
TEST_OUTPUT: |
| 6 |
--- |
| 7 |
fail_compilation/dtorfields_attributes.d(117): Error: `pure` constructor `dtorfields_attributes.Strict.this` cannot call impure destructor `dtorfields_attributes.Strict.~this` |
| 8 |
fail_compilation/dtorfields_attributes.d(119): generated `Strict.~this` is impure because of the following field's destructors: |
| 9 |
fail_compilation/dtorfields_attributes.d(115): - HasDtor member |
| 10 |
fail_compilation/dtorfields_attributes.d(103): impure `HasDtor.~this` is declared here |
| 11 |
fail_compilation/dtorfields_attributes.d(117): Error: `@safe` constructor `dtorfields_attributes.Strict.this` cannot call `@system` destructor `dtorfields_attributes.Strict.~this` |
| 12 |
fail_compilation/dtorfields_attributes.d(119): `dtorfields_attributes.Strict.~this` is declared here |
| 13 |
fail_compilation/dtorfields_attributes.d(119): generated `Strict.~this` is @system because of the following field's destructors: |
| 14 |
fail_compilation/dtorfields_attributes.d(115): - HasDtor member |
| 15 |
fail_compilation/dtorfields_attributes.d(103): @system `HasDtor.~this` is declared here |
| 16 |
fail_compilation/dtorfields_attributes.d(117): Error: `@nogc` constructor `dtorfields_attributes.Strict.this` cannot call non-@nogc destructor `dtorfields_attributes.Strict.~this` |
| 17 |
fail_compilation/dtorfields_attributes.d(119): generated `Strict.~this` is non-@nogc because of the following field's destructors: |
| 18 |
fail_compilation/dtorfields_attributes.d(115): - HasDtor member |
| 19 |
fail_compilation/dtorfields_attributes.d(103): non-@nogc `HasDtor.~this` is declared here |
| 20 |
--- |
| 21 |
*/ |
| 22 |
#line 100 |
| 23 |
|
| 24 |
struct HasDtor |
| 25 |
{ |
| 26 |
~this() |
| 27 |
{ |
| 28 |
// Enforce @system, ... just to be sure |
| 29 |
__gshared int i; |
| 30 |
if (++i) |
| 31 |
throw new Exception(new immutable(char)[](10)); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
// The user-defined dtor matches the ctor attributes |
| 36 |
struct Strict |
| 37 |
{ |
| 38 |
HasDtor member; |
| 39 |
|
| 40 |
this(int) pure @nogc @safe {} // nothrow doesn't generate dtor call |
| 41 |
|
| 42 |
~this() pure @nogc @safe {} |
| 43 |
} |