[Issue 17652] New: [DIP1000] opApply allow to escape reference to scope variable
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Jul 14 08:25:08 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17652
Issue ID: 17652
Summary: [DIP1000] opApply allow to escape reference to scope
variable
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: safe
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: mathias.lang at sociomantic.com
```
void main () @safe @nogc
{
Object o = leak();
assert(o !is null);
}
Object leak () @safe @nogc
{
Foo f;
foreach (object; f)
if (object !is null)
return object;
return null;
}
struct Foo
{
alias DgType = int delegate (scope Object) @safe @nogc;
public int opApply (scope DgType dg) @safe @nogc
{
scope o = new Object;
return dg(o);
}
}
```
The compiler doesn't properly check the type of the delegate it passes to
`opApply`, allowing to pass a delegate which needs a non-scope parameter.
--
More information about the Digitalmars-d-bugs
mailing list