[Issue 18738] New: [scope] scope delegates can be escaped via closure
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Apr 6 15:13:26 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=18738
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
Assignee: nobody at puremagic.com
Reporter: default_357-line at yahoo.de
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.
--
More information about the Digitalmars-d-bugs
mailing list