[Issue 1330] New: Array slicing does not work the same way in CTFE as at runtime

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jul 10 19:34:50 PDT 2007


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

           Summary: Array slicing does not work the same way in CTFE as at
                    runtime
           Product: D
           Version: 1.018
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: jarrett.billingsley at gmail.com


Example:

char[] Something(char[] blah)
{
        char[] slice = blah[0 .. 1];
        slice[0] = 'h';
        return blah;
}

void main()
{
        pragma(msg, Something("foo".dup));
        writefln("%s", Something("foo".dup));
}

When compiled, this displays "foo"; when run, "hoo".  Notice that slicing the
input array and then modifying the slice is supposed to modify the original
array, but it doesn't in CTFE because Slice() in the frontend always creates a
copy of the data.


-- 



More information about the Digitalmars-d-bugs mailing list