www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13531] New: Destructor attributes don't take member


          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 puremagic.com
          Reporter: monarchdodra gmail.com

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

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- 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

Sep 25 2014