Bug 1330 – Array slicing does not work the same way in CTFE as at runtime

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-07-10T21:34:00Z
Last change time
2014-02-16T15:24:12Z
Keywords
wrong-code
Assigned to
nobody
Creator
jarrett.billingsley
Blocks
4050, 4051

Comments

Comment #0 by jarrett.billingsley — 2007-07-10T21:34:50Z
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.
Comment #1 by clugdbug — 2009-12-29T00:12:38Z
*** Issue 3456 has been marked as a duplicate of this issue. ***
Comment #2 by clugdbug — 2010-04-03T11:20:23Z
*** Issue 4057 has been marked as a duplicate of this issue. ***
Comment #3 by clugdbug — 2011-04-08T21:16:15Z
Comment #4 by clugdbug — 2011-05-06T01:48:15Z
*** Issue 5907 has been marked as a duplicate of this issue. ***