https://issues.dlang.org/show_bug.cgi?id=20868

--- Comment #8 from RazvanN <[email protected]> ---
(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-@safe
could, however, if the function is @safe it would still be an error.

--

Reply via email to