No warning for unreachable code
Segher Boessenkool
segher@kernel.crashing.org
Tue Jun 3 22:47:00 GMT 2008
> 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();
}
==
More information about the Gcc
mailing list