Bug 23587 - Missing "warning: comparison is always false due to limited range of data type"
: Missing "warning: comparison is always false due to limited range of data type"
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c
: 4.1.0
: P2 normal
: 4.3.0
Assigned To: Not yet assigned to anyone
:
: diagnostic
:
:
  Show dependency treegraph
 
Reported: 2005-08-27 00:10 UTC by v.haisman
Modified: 2007-05-20 21:42 UTC (History)
4 users (show)

See Also:
Host: i386-unknown-freebsd4.10
Target: i386-unknown-freebsd4.10
Build: i386-unknown-freebsd4.10
Known to work:
Known to fail: 2.95.3 3.2.3 3.4.0 4.0.0 4.1.0
Last reconfirmed: 2006-01-24 04:33:08


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description v.haisman 2005-08-27 00:10:58 UTC
The following test warns about the comparison being always true only for two of
 the six tests:

#include <cstdlib>

void a (unsigned char x)
{
  if (x < 0)
    abort ();
}

void b (unsigned short x)
{
  if (x < 0)
    abort ();
}

void c (unsigned int x)
{
  if (x < 0)
    abort ();
}

void d (unsigned long x)
{
  if (x < 0)
    abort ();
}

void e (unsigned long long x)
{
  if (x < 0)
    abort ();
}

void f (size_t x)
{
  if (x < 0)
    abort ();
}


wilx@logout:::~/tmp> g++ -save-temps -fverbose-asm -O3 -c test.cxx
test.cxx: In function 'void a(unsigned char)':
test.cxx:5: warning: comparison is always false due to limited range of data type
test.cxx: In function 'void b(short unsigned int)':
test.cxx:11: warning: comparison is always false due to limited range of data type


wilx@logout:::~/tmp> g++ -v
Using built-in specs.
Target: i386-unknown-freebsd4.10
Configured with: ../srcdir/configure --disable-nls
--enable-version-specific-runtime-libs --enable-dwarf2 --with-cpu=pentium3
--with-arch=pentium3 --with-system-zlib --disable-shared --prefix=/home/4/wilx
--enable-languages=c,c++,objc,ada --disable-sjlj-exceptions
--enable-shared=libstdc++ --enable-shared=libobjc
Thread model: posix
gcc version 4.1.0 20050821 (experimental)
Comment 1 Andrew Pinski 2005-10-25 20:23:21 UTC
We do have an inconstaincy here, with -W, I get a  warning for all 6 of them.
Comment 2 Andrew Pinski 2005-10-25 20:24:04 UTC
t.c: In function ‘void c(unsigned int)’:
t.c:17: warning: comparison of unsigned expression < 0 is always false
t.c: In function ‘void d(long unsigned int)’:
t.c:23: warning: comparison of unsigned expression < 0 is always false
t.c: In function ‘void e(long long unsigned int)’:
t.c:29: warning: comparison of unsigned expression < 0 is always false
Comment 3 Pawel Sikora 2007-01-23 20:15:24 UTC
*** Bug 29694 has been marked as a duplicate of this bug. ***
Comment 4 Manuel López-Ibáñez 2007-05-20 21:31:57 UTC
Subject: Bug 23587

Author: manu
Date: Sun May 20 20:29:55 2007
New Revision: 124875

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124875
Log:
2007-05-20  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

    PR middle-end/7651
    PR c++/11856
    PR c/12963
    PR c/23587
    PR other/29694
    * c.opt (Wtype-limits): New.
    * doc/invoke.texi (Wtype-limits): Document it.
    (Wextra): Enabled by -Wextra.
    * c-opts.c (c_common_post_options): Enabled by -Wextra.
    * c-common.c (shorten_compare): Warn with Wtype-limits.

testsuite/
    * gcc.dg/compare6.c: Replace Wall with Wtype-limits.
    * gcc.dg/Wtype-limits.c: New.
    * gcc.dg/Wtype-limits-Wextra.c: New.
    * gcc.dg/Wtype-limits-no.c: New.
    * g++.dg/warn/Wtype-limits.C: New.
    * g++.dg/warn/Wtype-limits-Wextra.C: New.
    * g++.dg/warn/Wtype-limits-no.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wtype-limits-Wextra.C
    trunk/gcc/testsuite/g++.dg/warn/Wtype-limits-no.C
    trunk/gcc/testsuite/g++.dg/warn/Wtype-limits.C
    trunk/gcc/testsuite/gcc.dg/Wtype-limits-Wextra.c
    trunk/gcc/testsuite/gcc.dg/Wtype-limits-no.c
    trunk/gcc/testsuite/gcc.dg/Wtype-limits.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-opts.c
    trunk/gcc/c.opt
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/compare6.c
Comment 5 Manuel López-Ibáñez 2007-05-20 21:42:44 UTC
Fixed for GCC 4.3 (all warnings have been grouped under -Wtype-limits).