Bug 8974 – closure delegate might break preceding code

Status
RESOLVED
Resolution
DUPLICATE
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-11-07T14:52:00Z
Last change time
2012-11-08T21:15:15Z
Keywords
wrong-code
Assigned to
nobody
Creator
fawzi

Comments

Comment #0 by fawzi — 2012-11-07T14:52:41Z
I found the particularly nasty example where introducing a non scoped delegate breaks the preceding loop with DMD 2.060. ------------- module t6; import core.stdc.stdio; void ff(T)(T[] arr1){ T[] copyArr=new T[](arr1.length); size_t ii=0; foreach(size_t i,T e;arr1){ // i is invalid, accessing did segfaults in the original bug // changing the delegate below (to remove code dep) it is now "only" invalid printf("i=%ld\n",i); scope dl=delegate void(int sink){ if (i>10) assert(0); }; } ii=0; // using a scoped delegate here removes the bug auto dlg=delegate bool(ref T*el){ if (ii<1){ // originally also ++ii; return true; } return false; }; } int main(string[]args){ int[]narr=new int[](3); ff(narr); return 0; } ----------
Comment #1 by k.hara.pg — 2012-11-08T21:15:15Z
*** This issue has been marked as a duplicate of issue 8526 ***