www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5846] New: String literals can be assigned to static char arrays without .dup

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5846

           Summary: String literals can be assigned to static char arrays
                    without .dup
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com



10:36:37 PDT ---
Isn't the following invalid code?

char[3] value = "abc";

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 16 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5846


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |schveiguy yahoo.com
         Resolution|                            |INVALID



06:07:35 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 18 2011