Thread overview
[Issue 13531] Destructor attributes don't take member destructor attributes into account
Nov 13, 2014
Walter Bright
Jul 08, 2015
Kenji Hara
Dec 08, 2021
Stanislav Blinov
Dec 17, 2022
Iain Buclaw
November 13, 2014
https://issues.dlang.org/show_bug.cgi?id=13531

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com
           Severity|normal                      |minor

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
What's happening here is that there are actually two destructors for SS - the one for the s field, and the ~this(). The compiler combines all such destructors into one aggregate destructor. The aggregate destructor contains the most permissive combination of the attributes of all the aggregated destructors.

The error message is for the generated aggregated destructor.

Perhaps the error message could be better, but the feature is working as designed.

Reducing this issue to minor as the only problem is the error message.

--
July 08, 2015
https://issues.dlang.org/show_bug.cgi?id=13531

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--
December 08, 2021
https://issues.dlang.org/show_bug.cgi?id=13531

Stanislav Blinov <stanislav.blinov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |stanislav.blinov@gmail.com

--- Comment #2 from Stanislav Blinov <stanislav.blinov@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-@nogc destructor
`SS.~this`
main.d(10):        generated `SS.~this` is non-@nogc because of the following
field's destructors:
main.d(9):         - S s
main.d(3):           non-@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.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=13531

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 13
https://issues.dlang.org/show_bug.cgi?id=13531

--- Comment #3 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18891

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--