[Issue 13531] Destructor attributes don't take member destructor attributes into account
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Dec 8 18:00:46 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=13531
Stanislav Blinov <stanislav.blinov at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |stanislav.blinov at gmail.com
--- Comment #2 from Stanislav Blinov <stanislav.blinov at gmail.com> ---
Nowadays the error message is... better, for a conservative definition of
"better". But it's __very__ verbose and most of all, wrong. It's referring to
SS.~this, which is not at all the destructor in question - SS.__xdtor is. It's
even referring to the line where SS.~this is declared! SS.~this has the
attributes, and the error message shouldn't indicate that it doesn't.
main.d(16): Error: `pure` function `D main` cannot call impure destructor
`SS.~this`
main.d(10): generated `SS.~this` is impure because of the following
field's destructors:
main.d(9): - S s
main.d(3): impure `S.~this` is declared here
main.d(16): Error: `@safe` function `D main` cannot call `@system` destructor
`SS.~this`
main.d(10): `SS.~this` is declared here
main.d(10): generated `SS.~this` is @system because of the following
field's destructors:
main.d(9): - S s
main.d(3): @system `S.~this` is declared here
main.d(16): Error: `@nogc` function `D main` cannot call non- at nogc destructor
`SS.~this`
main.d(10): generated `SS.~this` is non- at nogc because of the following
field's destructors:
main.d(9): - S s
main.d(3): non- at nogc `S.~this` is declared here
main.d(16): Error: destructor `SS.~this` is not `nothrow`
main.d(10): generated `SS.~this` is not nothrow because of the following
field's destructors:
main.d(9): - S s
main.d(3): not nothrow `S.~this` is declared here
main.d(14): Error: `nothrow` function `D main` may throw
Add more fields to SS, and this gets even longer.
With this code:
struct S
{
~this() //not nothrow, system, impure, gc etc...
{}
}
struct S2
{
~this() {}
}
struct SS
{
S s;
~this() @safe pure nothrow @nogc
{}
}
struct SSS
{
SS ss;
~this() @safe pure nothrow @nogc {}
}
void main() @safe pure nothrow @nogc
{
SSS ss;
}
...errors are page long :\
Suggested change:
main.d(16): Error: `@safe pure nothrow @nogc` function `D main` cannot call
impure @system throwing GC-using generated destructor for `SS`
main.d(9): Generated destructor for `SS` is impure @system throwing GC-using
because of destructor of field `s`
main.d(3): impure @system throwing GC-using destructor of field `s` is declared
here
...with one relevant line per field, correctly distinguishing generated
destructors and user-defined destructors.
--
More information about the Digitalmars-d-bugs
mailing list