[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 08:21:04 UTC 2021


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

--- Comment #6 from RazvanN <razvan.nitu1305 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
>   }
> 
> and there is no error without -dip1000.
> 
> The first thing to do is simplify:
> 
>   void scoped (scope void* p) {
>     static void*[] px;
>     px ~= p;
>   }
> 
> which exhibits the same behavior. But let's try this:
> 
>   void scoped (scope void* p) {
>     static void* px;
>     px = p;
>   }
> 
> which generates no error with or without -dip1000. Marking the function with
> @safe yields:
> 
>    Error: scope variable p is assigned to non-scope px
> 
> with or without -dip1000.
> 
> The examples must behave the same way. They don't, so which is right? The
> array examples are wrong.

So you agree with the PR I made? It essentially makes the error at line `dgs ~=
dg;` go away in -dip1000 context.

--


More information about the Digitalmars-d-bugs mailing list