Bug 8306 – alias 'array' this consumes array on iteration

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-27T01:05:00Z
Last change time
2012-07-01T01:32:02Z
Assigned to
nobody
Creator
tobias

Attachments

IDFilenameSummaryContent-TypeSize
1121bug2.dcode showing the bugtext/x-dsrc827

Comments

Comment #0 by tobias — 2012-06-27T01:05:37Z
Created attachment 1121 code showing the bug The attached program produces buggy code. This code stores an index (a list of Agg*) to some Agg and prints all Agg currently in this index. Then it prints every Agg in turn. In the foreach loop every agg is empty. Which is wrong. It works however, if I comment out the alias content this; line or if I don't print the index before the loop. struct A { int a; int b; } struct Agg { A[] content; alias content this; } void main(string[] args) { Agg* agg = new Agg; A l1 = A((1), (2)); A l2 = A((2), (3)); A l3 = A((3), (4)); agg.content ~= [l1, l2, l3]; Agg*[] aggIndex = [agg]; writefln("these are the %s aggregates:\n%s", aggIndex.length, aggIndex); foreach(Agg* myAgg; aggIndex) { A[] as = (*myAgg).content; writefln("current agg %s with length %s", as, as.length); } }
Comment #1 by issues.dlang — 2012-06-27T01:29:29Z
On the latest master, I get the exact same behavior regardless of whether the alias is there. I always get these are the 1 aggregates: [7F3AB1ECEFF0] current agg [A(1, 2), A(2, 3), A(3, 4)] with length 3 and commenting out the first print statement has no effect on the second.
Comment #2 by tobias — 2012-07-01T01:32:02Z
Can not reproduce with git master, too.