Bug 15247 – Object's destructor should be pure @safe nothrow @nogc
Status
RESOLVED
Resolution
INVALID
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-10-25T13:51:00Z
Last change time
2016-06-19T01:42:05Z
Keywords
safe
Assigned to
nobody
Creator
andrei
Comments
Comment #0 by andrei — 2015-10-25T13:51:32Z
The destructor of Object does nothing so it should not be maximally conservative (as is today). User-defined classes should inherit the pure @safe nothrow @nogc attributes for destructor.
If a user-defined class includes fields that have destructors, the generated destructor will also generate the attributes appropriately.
Comment #1 by dfj1esp02 — 2015-10-26T10:15:02Z
What should happen to impure destructors?
Comment #2 by andrei — 2015-10-26T13:04:38Z
(In reply to Sobirari Muhomori from comment #1)
> What should happen to impure destructors?
They just are introduced as impure and work (because they may call pure destructors).
Comment #3 by Marco.Leise — 2015-10-27T17:33:39Z
class D
{
~this() @system {}
}
void main()
{
foo(new D);
}
void foo(Object o) pure @safe nothrow @nogc
{
o.destroy(); // Whatever we call it...
}
What I'm saying here is, if destructors were virtual methods that inherit and recursively call their base class destructors, and we had pure @safe nothrow @nogc on Object, we could NOT actually introduce impure destructors, as the compiler cannot statically verify attributes that may be loosened in a derived class. Attributes can only be added to overridden methods never removed, the same way methods can only be added and not removed. This bug report is invalid, in my humble opinion.
Comment #4 by bugzilla — 2016-06-19T01:42:05Z
Marco is correct. Overriding functions can increase restrictions, but not decrease them.