Bug#190757: please add a warning for conversion from "int" to "unsigned int"
On Fri, Apr 25, 2003 at 05:41:20PM +0200, Robert Millan wrote:
> Package: gcc-3.2
> Version: 1:3.2.3-0pre9
> Severity: wishlist
> the following code (compiled with -Wall -pedantic) could be
> considered "buggy", because it implicitly converts a
> signed int to unsigned int when calling "a". if you run it,
> it will print the number 2^32-1 instead of -1.
> #include <stdio.h>
> int a (unsigned int b)
> return printf ("%u\n", b);
> int main ()
> return a (-1);
> this can lead to programming bugs. to prevent a programmer from
> such, i'd appreciate if gcc said something like:
> warning: implicit conversion from signed to unsigned
> when asked to compile this code.
> maybe it makes sense to warn about conversion from unsigned to
> signed too, although having problems with this is unlikely,
> since bit overflow only happens with really big numbers.
Is this roughly what you want:
drow@nevyn:~% gcc-3.2 -Wall -Wconversion -c c.c
c.c: In function `main':
c.c:8: warning: passing arg 1 of `a' as unsigned due to prototype
c.c:8: warning: negative integer implicitly converted to unsigned type
It's not part of -Wall because it's too noisy.
MontaVista Software Debian GNU/Linux Developer