← Back to index
|
Original Bugzilla link
Bug 6141 – Bad code with ref-foreach and closures
Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-06-10T02:18:00Z
Last change time
2012-11-09T05:48:42Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
dlang-bugzilla
Comments
Comment #0
by dlang-bugzilla — 2011-06-10T02:18:34Z
void takeADelegate(void delegate()) {} void main() { auto items = new int[1]; items[0] = 17; foreach (ref item; items) { // both asserts fail assert(item == 17); assert(&item == items.ptr); takeADelegate({ auto x = &item; }); } }
Comment #1
by dlang-bugzilla — 2011-11-01T19:00:36Z
Hit this again. Raising priority, since it causes "mysterious crashes".
Comment #2
by verylonglogin.reg — 2012-04-22T06:21:39Z
Looks like the same issue: --- void main() { foreach(ref val; [3]) { auto del = { int j = val; }; assert(&val != null); // Assertion failure assert(val == 3); } } --- and --- void f(lazy int) { } void main() { int i = 0; auto del = { int j = i; }; foreach(ref val; [3]) { f(val); assert(&val != null); // Assertion failure assert(val == 3); } } ---
Comment #3
by k.hara.pg — 2012-11-09T02:18:16Z
https://github.com/D-Programming-Language/dmd/pull/1272
Comment #4
by github-bugzilla — 2012-11-09T04:16:03Z
Commits pushed to master at
https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/26870291ebcb9512bc3c7a3099719b3ef8596bd7
fix Issue 6141 - Bad code with ref-foreach and closures
https://github.com/D-Programming-Language/dmd/commit/8fc3e4b59bf5786accee257d301ca8de8cf8a277
Merge pull request #1272 from 9rnsr/fix8526 Issue 8526 & 6141 - DMD 2.060 regression: anonymous delegate call in foreach loop