Bug 5671 – CTFE string concat problem

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-03-01T04:56:00Z
Last change time
2011-04-18T16:02:31Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-03-01T04:56:19Z
A problem found by Peter Lundgren and David Nadlinger. Reduced D2 code: import std.conv: to; string foo() { // return to!string(10); // OK return to!string(10) ~ ""; } string s = foo(); void main() {} DMD 2.052 gives the errors: test.d(4): Error: to(10) ~ "" cannot be interpreted at compile time test.d(6): Error: cannot evaluate foo() at compile time test.d(6): Error: cannot evaluate foo() at compile time I think it's not a problem of to!() because this alternative version works correctly: import std.conv: to; string foo() { return to!string(10); } string s = foo(); void main() {}
Comment #1 by clugdbug — 2011-03-01T05:08:35Z
Reduced test case shows it is a constant folding problem. ['a', 'b'] ~ "c" doesn't get constant folded. string foo5671() { return ['a', 'b']; } string bug5671() { return foo5671() ~ "c"; } static assert(bug5671() == "abc");
Comment #2 by clugdbug — 2011-03-05T17:56:46Z
Can be reduced even further, showing CTFE isn't involved at all: static assert( ['a', 'b'] ~ "c" == "abc" );
Comment #3 by bugzilla — 2011-04-18T16:02:31Z