This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

spurious signedness warnings


Hi,
I am getting what I consider spurious warnings about the signedness of
function arguments. the compiler is the 19980628 snapshot, this
behaviour is different to the 1.0.3a release. Here is an example

--begin program
typedef unsigned int UI;

void f1(UI);
void f2(unsigned);

void f3()
{
  f1(-1);           // call 1
  f1(-(UI)1);       // call 2
  f1(-(unsigned)1); // call 3
  f2(-1);           // call 4
  f2(-(UI)1);       // call 5
  f2(-(unsigned)1); // call 6
}     
--end program

here is the session log
--begin log
nathan@laie:9952>uname -a                  
SunOS laie 5.5.1 Generic sun4u sparc SUNW,Ultra-1

nathan@laie:9953>egcs-0628-g++ -W -c foo.cc -v
Reading specs from
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.43/specs
gcc version egcs-2.91.43 19980628 (gcc2 ss-980502 experimental)

/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.43/cpp
-lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus
-D__GNUC_MINOR__=91 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__
-D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix
-Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -W -D__GCC_NEW_VARARGS__
-Acpu(sparc) -Amachine(sparc) foo.cc /var/tmp/ccniD1IZ
GNU CPP version egcs-2.91.43 19980628 (gcc2 ss-980502 experimental)
(sparc)
#include "..." search starts here:
#include <...> search starts here:
 /home/staff/nathan/solaris/local/include/g++
 /usr/local/include
 /home/staff/nathan/solaris/local/SunOS_5/sparc-sun-solaris2.5.1/include

/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.43/include
 /usr/include
End of search list.

/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.43/cc1plus
/var/tmp/ccniD1IZ -quiet -dumpbase foo.cc -W -version -o
/var/tmp/cc6Gqv8S
GNU C++ version egcs-2.91.43 19980628 (gcc2 ss-980502 experimental)
(sparc-sun-solaris2.5.1) compiled by GNU C version 2.8.1.
foo.cc: In function `void f3()':
foo.cc:8: warning: negative value `-1' passed as argument 1 of `f1(UI)'
foo.cc:9: warning: negative value `0ffffffff' passed as argument 1 of
`f1(UI)'
foo.cc:10: warning: negative value `0ffffffff' passed as argument 1 of
`f1(UI)'
foo.cc:11: warning: negative value `-1' passed as argument 1 of
`f2(unsigned int)'
 /usr/ccs/bin/as -V -Qy -s -o foo.o /var/tmp/cc6Gqv8S
/usr/ccs/bin/as: SC4.2 dev 30 Nov 1995
--end log

I agree about the warnings for lines 8 and 11, as here I've invoked
implementation defined behaviour of converting a negative signed value
to an unsigned range. I'm surprised about the warnings for lines 9 and
10. Both of these negate an unsigned type, which is defined by the
standard as the same as subtracting from unsigned zero, which is in turn
defined to behave in a modulo manner. Therefore I have not invoked
non-conforming behaviour and am passing the largest possible unsigned
value. A wierdness is that the warning is happening when the underlying
parameter type is hidden via a typedef and not when it is explicit. I
guess the logic here is that if the parameter type is a typedef, I could
have forgotten that it's unsigned. I don't buy that argument because
some typedefs I *know* are unsigned (like size_t).

The 1.0.3a release only warns about lines 8 and 11. That is the
behaviour I'd expect.

What is the reasoning behind giving me warnings on lines 9 and 10? (btw,
`0ffffffff' doesn't look like a negative number to me). I'm finding it
objectionable, particularly because when I have
	void fn(size_t arg = -(size_t)1);
in a header file, all uses of that function get the warning, even though
nothing's wrong.

BTW, I like compiling with warnings, because (until now) g++'s warnings
are extremely helpful. If it is decided that the above warning is
desirable, *PLEASE* do not enable it with -W, but with a separate flag.
(The warnings for lines 8 and 11 are good, and should be diagnosed on -W
though.)

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]