Bug 3617 – CTFE: wrong code for if(x) where x is int or smaller
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Windows
Creation time
2009-12-15T14:12:00Z
Last change time
2014-04-18T09:12:08Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
clugdbug
Comments
Comment #0 by clugdbug — 2009-12-15T14:12:33Z
Applies to while(), if(), assert(), etc.
Also happens if you have (say) uint u = 0x8000_0000; u<<=1;
-- since this sets the high bit of the value to 1.
TEST CASE:
----
int foo() {
int u = cast(int)(0x1_0000_0000L);
while (u) {
if (u) {
assert(u!=0);
}
assert(u!=0);
}
return 2;
}
static assert(foo()==2);
--------------------
PATCH: expression.c, around line 1575.
Need to convert the value to an appropriate sized integer.
int IntegerExp::isBool(int result)
{
+ toInteger();
return result ? value != 0 : value == 0;
}
Comment #1 by leandro.lucarella — 2009-12-15T16:50:30Z