[Issue 6052] New: [CTFE] Structs elements in an array are treated like reference type
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue May 24 09:11:13 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6052
Summary: [CTFE] Structs elements in an array are treated like
reference type
Product: D
Version: D2
Platform: Other
OS/Version: Mac OS X
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: kennytm at gmail.com
--- Comment #0 from kennytm at gmail.com 2011-05-24 09:06:57 PDT ---
Test case:
--------------------------------------------------
struct Bug6052 {
int a;
}
bool bug6052() {
Bug6052[2] arr;
for (int i = 0; i < 2; ++ i) {
Bug6052 el = {i};
Bug6052 ek = el;
arr[i] = el;
el.a = i + 2;
assert(ek.a == i); // ok
assert(arr[i].a == i); // fail
}
assert(arr[1].a == 1); // ok
assert(arr[0].a == 0); // fail
return true;
}
static assert(bug6052());
--------------------------------------------------
x.d(16): Error: assert(arr[cast(uint)i].a == i) failed
x.d(23): Error: cannot evaluate bug6052() at compile time
x.d(23): Error: static assert (bug6052()) is not evaluatable at compile time
--------------------------------------------------
Setting a struct value on a array should perform a bit-copy, so modifying 'el'
should not affect 'arr[i]', but currently CTFE does it wrongly.
--
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