D's Destructors are What Scott Meyers Warned Us About
sarn
sarn at theartofmachinery.com
Mon May 28 04:26:02 UTC 2018
On Sunday, 27 May 2018 at 22:27:52 UTC, sarn wrote:
> I've been thinking this through a bit, and here's what I've got
> so far:
Here's a tweak that should be implementable without any language
changes:
Instead of trying to detect an empty destructor, we use a UDA on
the class --- call it BaseObject or something. A
BaseObject-marked class is meant to be something like Andre's
ProtoObject, or a custom alternative base. It must not define a
destructor or include members with destructors (could relax this
in future but works for now), and must only inherit from other
BaseObject-marked classes.
With that, __vdtor could be implemented using a template mixin.
For a BaseObject class, that would generate an empty virtual
__vdtor. For other classes, it would call __xdtor and then
(non-virtually) call __vdtor for the superclass as long as it's
not a BaseObject class.
Can anyone see something I've missed? I think it works with the
current type system, makes Andre's ProtoObject possible while
supporting subclassing with @nogc or whatever, and gives us safe
class destructors that could be compatible with C++.
More information about the Digitalmars-d
mailing list