[Issue 15246] Destructor inheritance doesn't inherit attributes properly

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Apr 21 11:53:16 PDT 2017


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

Rainer Schuetze <r.sagitario at gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario at gmx.de

--- Comment #11 from Rainer Schuetze <r.sagitario at gmx.de> ---
See http://dlang.org/spec/class.html#destructors: "The destructor for the super
class automatically gets called when the destructor ends. There is no way to
call the super destructor explicitly."

I.e. the net effect of destructing an Object is the same as C++ virtual
destructor. It doesn't really matter how it is implemented, and the usage of
double underscores suggests that, too. Poking at the internals of __dtor,
__xdtor or rt_finalize should not have an effect on the language definition. 

Changing Andrei's example slightly with

void main() pure nothrow @safe @nogc {
    scope w = new Gadget;
}

compiles and generates the direct call to rt_finalize violating all the
attributes of main (but throws a FinalizeError due to throwing an exception -
this should only happen when called by the GC).

One option for keeping annotated class destructors useful without adding more
attributes: when checking attributes of the destructor of the derived class,
assume a trailing call to the base class destructor, but infer it's attributes
from the code. If no code is available for inference only the explicit
attributes are assumed (similar to declared (but not defined) functions in
templates!).

--


More information about the Digitalmars-d-bugs mailing list