[Issue 23136] New: closure in a loop should hold distinct values for each iteration
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue May 24 23:50:45 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23136
Issue ID: 23136
Summary: closure in a loop should hold distinct values for each
iteration
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: bugzilla at digitalmars.com
Reported by Timon Gehr.
This compiles even with -dip1000:
```d
import std.stdio;
void main()@safe{
void delegate()@safe[] dgList;
foreach(i; [1, 2, 3]) {
immutable b = i;
dgList ~= { writeln(b); };
}
foreach(dg; dgList) dg();
}
```
--
More information about the Digitalmars-d-bugs
mailing list