diff --git a/changelog/dmd.deprecation-dtor-fields.dd b/changelog/dmd.deprecation-dtor-fields.dd new file mode 100644 index 000000000000..d31290badf09 --- /dev/null +++ b/changelog/dmd.deprecation-dtor-fields.dd @@ -0,0 +1,32 @@ +An error is now given for constructors with field destructors with stricter attributes + +``` +struct HasDtor +{ + ~this() {} +} + +struct Pure +{ + HasDtor member; + this(int) pure {} // Error: `this` has stricter attributes than its destructor (`pure`) +} + +struct Nothrow +{ + HasDtor member; + this(int) nothrow {} // Error: `this` has stricter attributes than its destructor (`nothrow`) +} + +struct NoGC +{ + HasDtor member; + this(int) @nogc {} // Error: `this` has stricter attributes than its destructor (`@nogc`) +} + +struct Safe +{ + HasDtor member; + this(int) @safe {} // Error: `this` has stricter attributes than its destructor (`@safe`) +} +``` diff --git a/compiler/src/dmd/semantic3.d b/compiler/src/dmd/semantic3.d index 89c97cf6be4b..036bc6719697 100644 --- a/compiler/src/dmd/semantic3.d +++ b/compiler/src/dmd/semantic3.d @@ -1452,10 +1452,6 @@ private extern(C++) final class Semantic3Visitor : Visitor auto sexp = new ExpStatement(ctor.loc, ce); auto ss = new ScopeStatement(ctor.loc, sexp, ctor.loc); - // @@@DEPRECATED_2.106@@@ - // Allow negligible attribute violations to allow for a smooth - // transition. Remove this after the usual deprecation period - // after 2.106. if (global.params.dtorFields == FeatureState.default_) { auto ctf = cast(TypeFunction) ctor.type; @@ -1474,9 +1470,9 @@ private extern(C++) final class Semantic3Visitor : Visitor (puErr ? STC.pure_ : 0) | (saErr ? STC.system : 0) ); - ctor.loc.deprecation("`%s` has stricter attributes than its destructor (`%s`)", ctor.toPrettyChars(), ob.peekChars()); - ctor.loc.deprecationSupplemental("The destructor will be called if an exception is thrown"); - ctor.loc.deprecationSupplemental("Either make the constructor `nothrow` or adjust the field destructors"); + ctor.loc.error("`%s` has stricter attributes than its destructor (`%s`)", ctor.toPrettyChars(), ob.peekChars()); + ctor.loc.errorSupplemental("The destructor will be called if an exception is thrown"); + ctor.loc.errorSupplemental("Either make the constructor `nothrow` or adjust the field destructors"); ce.ignoreAttributes = true; } diff --git a/compiler/test/compilable/dtorfields_deprecation.d b/compiler/test/compilable/dtorfields_deprecation.d deleted file mode 100644 index 83014e38e471..000000000000 --- a/compiler/test/compilable/dtorfields_deprecation.d +++ /dev/null @@ -1,49 +0,0 @@ -/** -Checks that code still compiles when -preview=dtorfields is enabled by default -but issues an appropriate deprecation message. - -Remove this test when the deprecations period ends, see visit(CtorDeclaration) -in semantic3.d - -TEST_OUTPUT: ---- -compilable/dtorfields_deprecation.d(30): Deprecation: `dtorfields_deprecation.Pure.this` has stricter attributes than its destructor (`pure`) -compilable/dtorfields_deprecation.d(30): The destructor will be called if an exception is thrown -compilable/dtorfields_deprecation.d(30): Either make the constructor `nothrow` or adjust the field destructors -compilable/dtorfields_deprecation.d(42): Deprecation: `dtorfields_deprecation.NoGC.this` has stricter attributes than its destructor (`@nogc`) -compilable/dtorfields_deprecation.d(42): The destructor will be called if an exception is thrown -compilable/dtorfields_deprecation.d(42): Either make the constructor `nothrow` or adjust the field destructors -compilable/dtorfields_deprecation.d(48): Deprecation: `dtorfields_deprecation.Safe.this` has stricter attributes than its destructor (`@system`) -compilable/dtorfields_deprecation.d(48): The destructor will be called if an exception is thrown -compilable/dtorfields_deprecation.d(48): Either make the constructor `nothrow` or adjust the field destructors ---- -**/ - -struct HasDtor -{ - ~this() {} -} - -struct Pure -{ - HasDtor member; - this(int) pure {} -} - -struct Nothrow -{ - HasDtor member; - this(int) nothrow {} -} - -struct NoGC -{ - HasDtor member; - this(int) @nogc {} -} - -struct Safe -{ - HasDtor member; - this(int) @safe {} -}