Issue ID: 18738
           Summary: [scope] scope delegates can be escaped via closure
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd

Consider the following code:

int delegate() @safe foo(scope int delegate() @safe dg) @safe
    return { return dg(); };

int delegate() @safe bar() @safe
    int k = 5;
    return foo({ return k; });

void main() @safe
    writefln("%s", bar()());

The writefln outputs random noise because k is out of scope.

Doesn't seem very safe...

Probably foo should not have been allowed to allocate a closure that captured a
scope delegate parameter.


Reply via email to