void call(void delegate() callback) { callback(); } void f(int j, int i) { } void main() { foreach (int i, j; [0]) call({ f(j, i); }); } Works on 2.059, segfaults on 2.060. Tested on Win32 and Linux/64.
Works with DMD 1.075 Looks like it is D2 only. DMD2.060 fails both with m32/m64, on Linux and FreeBSD Current DMD2 trunk still has this bug.
*** Issue 8775 has been marked as a duplicate of this issue. ***
From bug 8775, foreach range statement has same bug. void call(void delegate() dg) { dg(); } void main() { foreach (i, j; [0]) { call({ assert(i == 0); // fails, i is corrupted }); } foreach (n; 0..1) { call({ assert(n == 0); // fails, n is corrupted }); } }
*** Issue 8974 has been marked as a duplicate of this issue. ***
https://github.com/D-Programming-Language/dmd/pull/1272
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/251a8bb0ede5e45bf5f41b60554a2962261516ff fix Issue 8526 - DMD 2.060 regression: anonymous delegate call in foreach loop This regression has occured from the commit: https://github.com/D-Programming-Language/dmd/commit/38a0a5141a3455395e8b9571a57bf85ed698c6b3 But the root cause is a bug in glue layer. When an internal ref variable is marked as closure var, the glue layer had generated incorrect code for that. 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