Compiler switch for integer comparison/promotion to catch a simple error
Dom Disc
dominikus at scherkl.de
Mon May 30 21:22:27 UTC 2022
On Sunday, 29 May 2022 at 01:35:23 UTC, frame wrote:
> Is there a compiler switch to catch this kind of error?
>
> ```d
> ulong v = 1;
> writeln(v > -1);
> ```
>
> IMHO the compiler should bail a warning if it sees a logic
> comparison between signed and unsigned / different integer
> sizes. There is 50% chance that a implicit conversion was not
> intended.
We have a solution for this problem in bugzilla:
https://issues.dlang.org/show_bug.cgi?id=259
This would allow for the above compare to simply work with all
integer types signed or unsigned and produce always the correct
result.
It was rejected because it would break old code that rely on this
misbehaviour (and even worse: the behaviour would be different
from what C does, oh my god!!)
More information about the Digitalmars-d-learn
mailing list