Summary: alias 'array' this consumes array on iteration
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Tobias Pankrath <> 2012-06-27 01:05:37 
PDT ---
Created an attachment (id=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",
    foreach(Agg* myAgg; aggIndex)
        A[] as = (*myAgg).content;
        writefln("current agg %s with length %s", as, as.length);

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to