D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7967 - Bad code with -inline, mismatching constness and array append
Summary: Bad code with -inline, mismatching constness and array append
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2012-04-22 11:18 UTC by siegelords_abode
Modified: 2013-11-26 19:39 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description siegelords_abode 2012-04-22 11:18:02 UTC
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
    }
}
Comment 1 siegelords_abode 2012-04-22 11:27:16 UTC
I meant 2.059 (although 2.058 probably has it too).
Comment 2 yebblies 2013-11-26 19:39:47 UTC
Works now.