Skip to content

Commit

Permalink
[Deprecation -> Error] destructor field attributes (#16802)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilsonator authored Aug 22, 2024
1 parent 796f5ce commit df377af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 56 deletions.
32 changes: 32 additions & 0 deletions changelog/dmd.deprecation-dtor-fields.dd
Original file line number Diff line number Diff line change
@@ -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`)
}
```
10 changes: 3 additions & 7 deletions compiler/src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
49 changes: 0 additions & 49 deletions compiler/test/compilable/dtorfields_deprecation.d

This file was deleted.

0 comments on commit df377af

Please sign in to comment.