mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
[Deprecation -> Error] destructor field attributes (#16802)
This commit is contained in:
parent
796f5cee9a
commit
df377af9fe
3 changed files with 35 additions and 56 deletions
32
changelog/dmd.deprecation-dtor-fields.dd
Normal file
32
changelog/dmd.deprecation-dtor-fields.dd
Normal file
|
@ -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`)
|
||||
}
|
||||
```
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue