[Issue 6052] [CTFE] Structs elements in an array are treated like reference type

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue May 31 01:39:09 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6052


kennytm at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |


--- Comment #3 from kennytm at gmail.com 2011-05-31 01:34:45 PDT ---
The bug still exists if the the struct has a constructor and we're appending to
a dynamic array....

---------------------------------------------
struct Bug6052c {
    int x;
    this(int a) { x = a; }
}
static assert({
    Bug6052c[] pieces = [];
    for (int c = 0; c < 2; ++ c)
        pieces ~= Bug6052c(c);
    assert(pieces[1].x == 1);   // ok
    assert(pieces[0].x == 0);   // asserts
    return true;
}());
---------------------------------------------
x.d(10): Error: assert(pieces[0u].x == 0) failed
<snipped>
---------------------------------------------

or filling the uninitialized portion of a dynamic array....

---------------------------------------------
static assert({
    int[1][] pieces = [];
    pieces.length = 2;
    for (int c = 0; c < 2; ++ c)
        pieces[c][0] = c;
    assert(pieces[1][0] == 1);   // ok
    assert(pieces[0][0] == 0);   // asserts
    return true;
}());
---------------------------------------------
x.d(7): Error: assert(pieces[0u][0u] == 0) failed
<snipped>
---------------------------------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list