Bug 5852 – CTFE: wrong code for string[] ~= const(string)
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-04-18T03:15:00Z
Last change time
2011-04-18T16:02:03Z
Keywords
wrong-code
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2011-04-18T03:15:36Z
int bug5852(const(string) s)
{
string [] r;
r ~= s;
assert(r.length == 1);
return r[0].length;
}
static assert(bug5852("abc")==3);
The (non-static) assert fails, and if it's commented out, you get:
test2.d(11): Error: integral constant must be scalar type, not string
test2.d(11): Error: cannot evaluate bug5852("abc") at compile time
test2.d(11): Error: static assert (bug5852("abc") == 3) is not evaluatable at c
ompile time
Comment #1 by kennytm — 2011-04-18T04:07:48Z
Correct code is generated only when the constness of the string match. Another example:
--------------------------------------
import std.stdio;
auto x(string y) {
const(string)[] z;
z ~= y;
z ~= y;
return z;
}
static assert(x("abc").length != 6);
--------------------------------------
Comment #2 by clugdbug — 2011-04-18T05:41:32Z
I've already got a fix for this one. Don't waste any time on it.