[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#190757: please add a warning for conversion from "int" to "unsigned int"



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.

-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux aragorn 2.2.22 #1 dl nov 25 21:59:43 CET 2002 i586
Locale: LANG=ca_ES.ISO-8859-1, LC_CTYPE=ca_ES@euro (ignored: LC_ALL set)

Versions of packages gcc-3.2 depends on:
ii  binutils                2.13.90.0.18-1.7 The GNU assembler, linker and bina
ii  cpp-3.2                 1:3.2.3-0pre9    The GNU C preprocessor
ii  gcc-3.2-base            1:3.2.3-0pre9    The GNU Compiler Collection (base 
ii  libc6                   2.3.1-17         GNU C Library: Shared libraries an
ii  libgcc1                 1:3.3-0pre5      GCC support library

-- no debconf information




Reply to: