Bug 5846 – String literals can be assigned to static char arrays without .dup

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-04-16T10:36:00Z
Last change time
2011-04-18T06:07:35Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
andrej.mitrovich

Comments

Comment #0 by andrej.mitrovich — 2011-04-16T10:36:37Z
Isn't the following invalid code? char[3] value = "abc";
Comment #1 by schveiguy — 2011-04-18T06:07:35Z
No. It is valid. value is allocated on the stack, or in TLS depending on where you declared it. Assigning it to the literal does not make it reference the actual literal data, it just copies the data into the value. In other words, changing an element of value does not change the immutable memory that the literal refers to.