www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7967] New: Bad code with -inline, mismatching constness and array append

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

           Summary: Bad code with -inline, mismatching constness and array
                    append
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: siegelords_abode yahoo.com



This happens with dmd 2.058 and probably earlier ones too. Compile the
following with dmd -inline. Note how the assertions fail when the constness of
the arguments to the array append doesn't match:

char[] toStr(char[] s)
{
    return s;
}

const(char)[] toStr(const(char)[] s)
{
    return s;
}

void main()
{
    {
        auto str = "abcd";
        const(char)[] res;
        res ~= toStr(str);
        assert(res == str); // Fine
    }

    {
        auto str = "abcd".dup;
        char[] res;
        res ~= toStr(str);
        assert(res == str); // Fine
    }

    {
        auto str = "abcd";
        char[] res;
        res ~= toStr(str);
        assert(res == str); // Fail
    }

    {
        auto str = "abcd".dup;
        const(char)[] res;
        res ~= toStr(str);
        assert(res == str); // Fail
    }
}

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




I meant 2.059 (although 2.058 probably has it too).

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