unsigned foo( unsigned i ) { if ( i < 0 ) i++; if ( i >= 0 ) i++; return i; } g++ 412svn/420svn with `-O2 -Wall' reports no errors.
Adding -W/-Wextra and we get a warning: t.c: In function ‘foo’: t.c:3: warning: comparison of unsigned expression < 0 is always false t.c:5: warning: comparison of unsigned expression >= 0 is always true I always forget what -Wextra is for.
(In reply to comment #1) > Adding -W/-Wextra and we get a warning: > t.c: In function �foo�: > t.c:3: warning: comparison of unsigned expression < 0 is always false > t.c:5: warning: comparison of unsigned expression >= 0 is always true > > > I always forget what -Wextra is for. what about -Walways-true ? <man> -Walways-true Warn about comparisons which are always true such as testing if unsigned values are greater than or equal to zero. This warning is enabled by -Wall. </man>
Wextra warns for this, what is the bug?
Subject: Re: missed warnings about comparisons which are always true/false. "manu at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: | Wextra warns for this, what is the bug? I believe pluto wants -Walways-true to cover this. -- Gaby
(In reply to comment #4) > Subject: Re: missed warnings about comparisons which are always true/false. > > "manu at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: > > | Wextra warns for this, what is the bug? > > I believe pluto wants -Walways-true to cover this. > I pity the poor guy that implements that. Linus will surely kill him/her.
This is a duplicate of PR 23587.
(In reply to comment #4) > Subject: Re: missed warnings about comparisons which are always true/false. > > "manu at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: > > | Wextra warns for this, what is the bug? > > I believe pluto wants -Walways-true to cover this. > > -- Gaby exactly. *** This bug has been marked as a duplicate of 23587 ***
Subject: Bug 29694 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