[Issue 12602] New: [CTFE] Changes to an array slice wrapped in a struct do not propogate to the original
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Apr 20 02:59:39 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=12602
Issue ID: 12602
Summary: [CTFE] Changes to an array slice wrapped in a struct
do not propogate to the original
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: dmitry.olsh at gmail.com
Simplified code, shows difference between R-T and C-T:
struct Result
{
uint[] source;
}
auto wrap(uint[] r)
{
return Result(r);
}
auto testWrap()
{
uint[] dest = [1, 2, 3, 4];
auto ra = wrap(dest[0..2]);
auto rb = wrap(dest[2..4]);
foreach (i; 0..2)
rb.source[i] = ra.source[i];
return dest;
}
@system void main()
{
static y = testWrap();
auto y2 = testWrap();
import std.conv;
assert(y == y2, text(y, " vs ", y2)); //[1, 2, 3 ,4] vs [1, 2, 1, 2]
}
Tested with DMD 9c34e808dd83ecf810a2f87c73c8d8a95e90b5cc
--
More information about the Digitalmars-d-bugs
mailing list