[Issue 6949] no warning or error if unsigned variable is compared to 0

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 29 16:26:53 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=6949


bearophile_hugs at eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs at eml.cc


--- Comment #2 from bearophile_hugs at eml.cc 2012-11-29 16:26:50 PST ---
I don't know if Walter will accept this change, but surely I welcome it a lot.
I have desired this in D since years.

For me one important use case of this warning is during code refactoring. Let's
say I have written code that uses some ints. Later for some reasons I turn one
or more of those ints into uints or size_ts. In such situation a warning like
this becomes very useful for me (I know it's useful because this warning has
avoided me troubles several times in C-GCC) because the warnings put in
evidence where the program contains code like "if (x < 0)". This means the code
requires that variable to be signed, or the program logic needs some changes.
Either way, the warning tells me the change I was doing is wrong and needs to
be undone or needs further changes.

Regarding how much common this kind of bug is in already debugged famous open
source programs, there is a kind of static analysis tool that has shown to spot
tens of similar bugs in that code. So this bug is common enough.

The disadvantages of this warning are probably some spurious warnings in
templated code. Is Phobos giving some warnings with this patch? More study is
probably needed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list