#dbugfix 17592
12345swordy
alexanderheistermann at gmail.com
Wed Mar 21 13:39:28 UTC 2018
On Wednesday, 21 March 2018 at 11:13:41 UTC, Simen Kjærås wrote:
> On Wednesday, 21 March 2018 at 08:49:11 UTC, Mike Franklin
> wrote:
>
>> I think `rt_finalize` can be made `@nogc` in the runtime.
>
> And this is where you're wrong. Consider this:
>
> class A {
> @nogc ~this() {}
> }
>
> class B : A {
> ~this() {}
> }
>
> A a = new B();
> destroy(a); // Is this @nogc?
>
>
> Essentially, since @nogc and other qualifiers aren't inherited
> on dtors, it's impossible to know if destroying an instance of
> a non-final class is @nogc.
>
> There's one case where you can: final classes where no
> superclass and no member defines a non- at nogc destructor.
>
> In order for this to be done in the general case, dtors need to
> inherit their qualifiers somehow. That's at the very least a
> DIP, and any chosen path is highly likely to break existing
> code.
>
> --
> Simen
You can simply check the .dtor symbols at compile time to see if
every .dtor symbol from child to root have a .dtor that have the
@nogc attribute(and other attributes as well). If it does, add
that attribute to destroy.
More information about the Digitalmars-d
mailing list