public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* gcc bug WRT warning that should not be displayed
@ 2007-03-16  0:38 Mo DeJong
  2007-03-19 19:56 ` Jim Wilson
  0 siblings, 1 reply; 2+ messages in thread
From: Mo DeJong @ 2007-03-16  0:38 UTC (permalink / raw)
  To: gcc-bugs

Hello

Gcc 3.4.2 on WinXP seems to generate a warning that it should not.

$ gcc -v
Reading specs from C:/msys/mingw/bin/../lib/gcc/mingw32/3.4.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as 
--host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads 
--disable-nls --enable-languages=c,c++,f77,ada,objc,java 
--disable-win32-registry --disable-shared --enable-sjlj-exceptions 
--enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm 
--disable-libgcj-debug --enable-interpreter 
--enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.2 (mingw-special)


The following C code shows the problem.

int foo() {
    long long val1 = 1; /* No warn when val1 is a long long */
    int c1 = (
          ((long long) val1) <
          ((long long)(-2147483647L - 1))
         );
    long val2 = 1; /* incorrect warn when val2 is a long */
    int c2 = (
          ((long long) val2) <
          ((long long)(-2147483647L - 1))
         );
    return (c1 || c2);
}

$ gcc -c test.c
test.c: In function `foo':
test.c:11: warning: comparison is always false due to limited range of 
data type

Both of the tests in the code above should compile without a warning, 
but the second one does not.

thanks much
Mo DeJong


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gcc bug WRT warning that should not be displayed
  2007-03-16  0:38 gcc bug WRT warning that should not be displayed Mo DeJong
@ 2007-03-19 19:56 ` Jim Wilson
  0 siblings, 0 replies; 2+ messages in thread
From: Jim Wilson @ 2007-03-19 19:56 UTC (permalink / raw)
  To: Mo DeJong; +Cc: gcc-bugs

Mo DeJong wrote:
>    long val2 = 1; /* incorrect warn when val2 is a long */
>    int c2 = (
>          ((long long) val2) <
>          ((long long)(-2147483647L - 1))
>         );

The result of the compare will always be false, so the warning is correct.

The long variable val2 can not hold a value smaller than LONG_MIN. 
Adding casts to long long does not change this fact.
-- 
Jim Wilson, GNU Tools Support, http://www.specifix.com


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-03-19 19:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-16  0:38 gcc bug WRT warning that should not be displayed Mo DeJong
2007-03-19 19:56 ` Jim Wilson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).