This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: No warning for unreachable code
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Guennadi Liakhovetski <g dot liakhovetski at gmx dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Wed, 4 Jun 2008 00:47:17 +0200
- Subject: Re: No warning for unreachable code
- References: <Pine.LNX.4.64.0806031832180.21106@axis700.grange>
I just discovered a behaviour in gcc-4, which I don't understand: code
unsigned int x;
if (x < 0)
do_something();
compiled with -Wall doesn't produce a warning, and the call to
do_something() is silently dropped, whereas if x is of type unsigned
char,
I get as expected
warning: comparison is always false due to limited range of data type
Is there a reason for such behaviour or is this a bug?
With -Wextra I get with both 4.2.4 and current TOT:
x.c: In function 'f_int':
x.c:5: warning: comparison of unsigned expression < 0 is always false
x.c: In function 'f_char':
x.c:11: warning: comparison is always false due to limited range of
data type
With just -Wall, 4.2.4 gives only the warning you mention, and TOT
gives nothing.
Are you suggesting that both warnings should be in -Wall? Or are
you telling us that you should be using -Wextra ;-)
Segher
x.c
==
void g(void);
void f_int(unsigned int x)
{
if (x < 0)
g();
}
void f_char(unsigned char x)
{
if (x < 0)
g();
}
==