[Issue 13531] New: Destructor attributes don't take member destructor attributes into account

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Sep 25 02:57:58 PDT 2014


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

          Issue ID: 13531
           Summary: Destructor attributes don't take member destructor
                    attributes into account
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: monarchdodra at gmail.com

If you have "S" with completely unsafe destructor, and you aggregate it into
"SS":

//----
struct S
{
    ~this() //not nothrow, system, impure, gc etc...
    {}
}

struct SS
{
    S s;
    ~this() @safe pure nothrow @nogc
    {}
}
//----

This compiles. This may or may not be wrong, depending on your point of view:
The "code content" of the destructor is indeed actually safe etc...

The issue comes if you actually do try to use it in a safe context:

//----
void main() @safe pure nothrow @nogc
{
    SS ss;
}
//----

Here is the error message:
//----
Error: pure function 'D main' cannot call impure function 'main.SS.~this'
Error: safe function 'D main' cannot call system function 'main.SS.~this'
Error: @nogc function 'D main' cannot call non- at nogc function 'main.SS.~this'
Error: 'main.SS.~this' is not nothrow
Error: function 'D main' is nothrow yet may throw
//----

The issue here is that it clearly states that "SS.~this" is the one that is
unsafe, yet it is clearly marked as such.

IMO, the bug is that it should have never been legally marked as @safe to begin
with.

--


More information about the Digitalmars-d-bugs mailing list