www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6815] New: Char array is turned into string expression during constant folding

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

           Summary: Char array is turned into string expression during
                    constant folding
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dawg dawgfoto.de



struct DChars
{
    dchar foo()
    {
        return ary[0];
    }

    dchar[] ary;
}

DChars get()
{
    DChars s;
    s.ary ~= 'H';
    s.ary ~= 'e';
    return s;
}

enum dchars = get().foo();
----

Which will bark:
Error: cannot cast a read-only string literal to mutable in CTFE

Cat in constfold.c turns null ~ char into a string expression
even though the type of null is not a string but a char array.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6815


Denis <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg gmail.com



---
Probably the same issue:
---
char[] f() {
    char[] buff = new char[1];
    buff[0] = 0; // works
    buff.ptr[0] = 0; // works
    *(&buff[0]) = 0; // works
    char* t = &buff[0]; *t = 0;   // error
    foreach(ref el; buff) el = 0; // error
    return buff; 
} 

static assert(f() == "\0");
---
Where `error` means: `Error: cannot cast a read-only string literal to mutable
in CTFE`

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 13 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6815





 Probably the same issue:
Nope, completely different. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 23 2012