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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 22 11:17:03 PDT 2012


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 at puremagic.com
        ReportedBy: siegelords_abode at yahoo.com


--- Comment #0 from siegelords_abode at yahoo.com 2012-04-22 11:18:02 PDT ---
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: -------


More information about the Digitalmars-d-bugs mailing list