www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11908] New: const(char)[] assigned to immutable(char)[] without error

https://d.puremagic.com/issues/show_bug.cgi?id=11908

           Summary: const(char)[] assigned to immutable(char)[] without
                    error
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: turkeyman gmail.com


--- Comment #0 from Manu <turkeyman gmail.com> 2014-01-12 09:25:49 PST ---
inout(char)[] todstr(inout(char)* cstr) pure nothrow
{
    return cstr ? cstr[0 .. std.c.string.strlen(cstr)] : cstr[0 .. 0];
}

struct Data
{
    char buffer[256] = void;
     property const(char)[] filename() const pure nothrow    { return
todstr(buffer.ptr); }
}

struct MyThing
{
    private this(in Data* p)
    {
        filename = p.filename; // *** Uh oh! assigned a const(char)[]  property
to a string! ***
    }

    string filename;
}

The const(char)[] is on the stack, program crashes soon after the assignment.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2014