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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Oct 27 10:24:01 PDT 2015


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

--- Comment #10 from Marco Leise <Marco.Leise at gmx.de> ---
Nope, in fact it is an extern(C) function, and I assume part of the druntime
API that people replace when writing bare metal runtimes etc.

Since destructors don't need to inherit attributes for anything based on the
current implementation, this bug report has no basis. If attributes were
inherited, it would not solve any use case or problem. If you meant to
streamline the language semantics with this, it was well meant, but actually
adds to the cognitive load.

Or did you have some specific use case in mind, like being able to
deterministically destroy objects in @safe functions? That's not going to
happen either way. As it stands now, `destroy(obj)` and `rt_finalize`, which is
neither @safe nor @nogc nor nothrow nor pure. And if we did in fact have
virtual destructors like C++, the general rule with inheritance applies: The
derived thing must be usable everywhere the base class is used. That disallows
the removal of attributes on virtual function overrides:

class C {
   ~this() @safe
}

class D {
   override ~this(); // @system
}

void foo(C c) @safe 
{
   // Destroying D is unsafe, but we can't statically check,
   // because for all we know it is at least a C.
   destroy(c);
}

void main()
{
   foo(new D);
}

--


More information about the Digitalmars-d-bugs mailing list