this code: cdouble c; int main() { if (c) return 0; return 1; } compiles with dmd 2.053 unless optimizations are turned on: c:\tmp>c:\l\dmd-2.053\windows\bin\dmd -O ccmp.d Internal error: ..\ztc\el.c 904
It seems, an optimization is tried with the comment "Try to replace (e1) with (e1 >= 1)", but does not work well with floating point numbers. It seems strange for integer values aswell. Here's a possible patch diff --git a/src/backend/cgelem.c b/src/backend/cgelem.c index 5cc6d48..be7a944 100644 --- a/src/backend/cgelem.c +++ b/src/backend/cgelem.c @@ -1752,7 +1752,7 @@ STATIC elem * elcond(elem *e) } } } - else + else if(tyintegral(e1->Ety)) e->E1 = el_bin(OPge,TYint,e1,el_long(touns(e1->Ety),1)); } #endif
https://github.com/D-Programming-Language/dmd/pull/452
Considering the patch, I realized that double c = 0.5; void main() { assert((c ? 0 : 1) == 0); } runs fine when compiled without -O, but asserts with -O.
The patch was merged 3 months ago. https://github.com/D-Programming-Language/dmd/commit/58507a208e12d0b7e44111f5eabd6747e5d79925