Bug 7967 – Bad code with -inline, mismatching constness and array append

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-22T11:18:00Z
Last change time
2013-11-26T19:39:47Z
Keywords
wrong-code
Assigned to
nobody
Creator
siegelords_abode

Comments

Comment #0 by siegelords_abode — 2012-04-22T11:18:02Z
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 by siegelords_abode — 2012-04-22T11:27:16Z
I meant 2.059 (although 2.058 probably has it too).
Comment #2 by yebblies — 2013-11-26T19:39:47Z
Works now.