Bug 2205 – Warning on comparison between signed and unsigned
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-07-08T14:16:00Z
Last change time
2015-06-09T05:15:05Z
Keywords
accepts-invalid
Assigned to
bugzilla
Creator
o.dathe
Comments
Comment #0 by o.dathe — 2008-07-08T14:16:44Z
The following code does not generate a warning when compiled with -w.
int a=-1;
uint b=1;
assert (a<b);
The assertion failes since the comparison is done unsigned. I think it is a very basic and frequent source of errors and should be taken into account if warnings are enabled - just like in gcc -W.
Comment #1 by smjg — 2008-07-08T19:48:31Z
I'd like this to either:
- be an error
- promote both sides to long
- generate some code resembling
assert (a < 0 || cast(uint) a < b);
Comment #2 by smjg — 2009-02-22T11:45:45Z
I've just checked, and by spec it's supposed to be an error.
*** This bug has been marked as a duplicate of 259 ***