On 01/27/2018 03:13 PM, kdevel wrote:
I would expect this code
enforce3.d
---
import std.exception;
void main ()
{
int i = int.min;
enforce (i > 0);
}
---
to throw an "Enforcement failed" exception, but it doesn't:
$ dmd enforce3.d
$ ./enforce3
[nothing]
Wow, that looks really bad.
Apparently, dmd implements `i < 0` as a `i >> 31`. I.e., it shifts the
bits to the right so far that only the sign bit is left. This is ok.
But it implements `i > 0` as `(-i) >> 31`. That would be correct if
negation would always flip the sign bit. But it doesn't for `int.min`.
`-int.min` is `int.min` again.
So dmd emits wrong code for `i > 0`. O_O
I've filed an issue:
https://issues.dlang.org/show_bug.cgi?id=18315