[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 16:27:01 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=20868
Bolpat <qs.il.paperinik at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |qs.il.paperinik at gmail.com
--- Comment #7 from Bolpat <qs.il.paperinik at gmail.com> ---
(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.
--
More information about the Digitalmars-d-bugs
mailing list