[Issue 20868] DIP1000: scope delegate triggers error in unsafe code and it shouldn't
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 14 18:27:35 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=20868
--- Comment #8 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to Bolpat from comment #7)
> (In reply to Walter Bright from comment #5)
> > To be specific, when compiled with -dip1000:
> >
> > void scoped (scope void delegate() dg) {
> > static void delegate()[] dgs;
> > dgs ~= dg; // Error: scope variable `dg` may not be copied into
> > allocated memory
> > }
>
> I only find the error message confusing. It should be an error: One cannot
> assign a scope object to a global state. Local static variables are not at
> global scope, but are a global state.
>
> Allowing that would make `scope` absolutely useless as a guarantee and for
> optimizations. When the function is called with a lambda, its can be
> allocated on the stack, because the reference won't "survive" the call. With
> allowing assignment to local static variables, this is no longer the case.
The DIP and spec say that scope analysis should be done only when dip1000 is
enabled and in @safe context. So this would make scope useless in non- at safe
could, however, if the function is @safe it would still be an error.
--
More information about the Digitalmars-d-bugs
mailing list