[Dlang-internal] DIP1000 discussion and testing

Walter Bright via Dlang-internal dlang-internal at puremagic.com
Mon Oct 24 16:10:46 PDT 2016


On 10/24/2016 2:13 AM, Mathias Lang wrote:
> Crafting a test case that exploit this was trivial:
> void* escape3 (scope void* p) @safe
> {
>     Escaper e;
>     scope dg = () { return e.e; };
>     e.e = p;
>     return dg();
> }

A complete example:

--------
struct Escaper { void* e; }

void* escape3 (scope void* p) @safe {
     Escaper e;
     e.e = p;
     scope dg = () { return e.e; }; // Error: scope variable e may not be returned
     return dg();
}
-------

But changing the order of things:

--------
struct Escaper { void* e; }

void* escape3 (scope void* p) @safe {
     Escaper e;
     scope dg = () { return e.e; }; // no error
     e.e = p;
     return dg();
}
-------

This definitely is a bug, but is fixable. Thanks for posting it!


More information about the Dlang-internal mailing list