Bug 29694 - missed warnings about comparisons which are always true/false.
Summary: missed warnings about comparisons which are always true/false.
Status: RESOLVED DUPLICATE of bug 23587
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-03 10:32 UTC by Pawel Sikora
Modified: 2007-01-23 20:15 UTC (History)
4 users (show)

See Also:
Host:
Target: ix86-linux
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2006-11-03 10:32:33 UTC
unsigned foo( unsigned i )
{
        if ( i < 0 )
                i++;
        if ( i >= 0 )
                i++;
        return i;
}

g++ 412svn/420svn with `-O2 -Wall' reports no errors.
Comment 1 Andrew Pinski 2006-11-03 10:39:03 UTC
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.
Comment 2 Pawel Sikora 2006-11-03 10:44:09 UTC
(In reply to comment #1)
> Adding -W/-Wextra and we get a warning:
> t.c: In function &#65533;foo&#65533;:
> 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>
Comment 3 Manuel López-Ibáñez 2007-01-09 15:21:58 UTC
Wextra warns for this, what is the bug?

Comment 4 Gabriel Dos Reis 2007-01-09 18:41:27 UTC
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
Comment 5 Manuel López-Ibáñez 2007-01-09 20:28:49 UTC
(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.
Comment 6 Manuel López-Ibáñez 2007-01-20 16:30:50 UTC
This is a duplicate of PR 23587.
Comment 7 Pawel Sikora 2007-01-23 20:15:24 UTC
(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 ***
Comment 8 Manuel López-Ibáñez 2007-05-20 21:31:56 UTC
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