Destructors can't be @nogc?
Mike Parker
aldacron at gmail.com
Sun Jul 25 04:09:04 UTC 2021
On Sunday, 25 July 2021 at 00:15:30 UTC, Jim wrote:
>
> But I think `destroy()` not being @nogc even though the
> destructor is tagged @nogc is a bug, and it should be fixed.
> Because it is problematic behaviour even if we limit the usage
> of @nogc.
It's not a bug. The destructor being tagged has nothing to do
with it. destroy can call @nogc destructors just fine. It just
can't itself be called in @nogc functions.
As Paul described, the root reason is down to rt_finalize. Were
it marked @nogc, then you could call destroy from @nogc code, but
you wouldn't be able to call destructors that aren't @nogc---an
even worse situation, IMO.
I think it's worth looking into how we can make destroy (or an
alternative) available in @nogc functions as an enhancement. It's
possible for extern(C) functions to be templated, so that might
be a potential path. With a templated rt_finalize (or an
alternative) then perhaps attribute inference could kick in and
make destroy (or an alternative) callable in both @nogc functions
and non.
More information about the Digitalmars-d-learn
mailing list