Bug 49706 - No warning for (!x > 1) which is always false
Summary: No warning for (!x > 1) which is always false
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.7.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 61276 (view as bug list)
Depends on: 64609 61271
Blocks:
  Show dependency treegraph
 
Reported: 2011-07-11 22:34 UTC by Andrew Pinski
Modified: 2022-01-09 00:47 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-07-12 08:51:27


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2011-07-11 22:34:38 UTC
Found this while looking into PR49474:
/* { dg-options "-Wextra -Wall" } */
void warn (void);
int f(int a)
{
  if (!a > 1) /* { dg-warning "false" } */
    warn();
  return 0;
}
Comment 1 Richard Biener 2011-07-12 08:51:27 UTC
Confirmed.
Comment 2 Jakub Jelinek 2011-07-12 09:27:38 UTC
-Wtype-limits is apparently just in shorten_compare and vrp, while here it is optimized by fold.  For
_Bool x;
...
if (x > 1)
or
struct { unsigned int i : 1; } x;
...
if (x.i > 1)
we don't warn either.
Comment 3 Andrew Pinski 2014-06-01 18:31:39 UTC
*** Bug 61276 has been marked as a duplicate of this bug. ***
Comment 4 Marek Polacek 2014-06-01 18:46:00 UTC
I have a patch implementing -Wlogical-not-parentheses.
Comment 5 Marek Polacek 2014-06-05 06:20:38 UTC
Author: mpolacek
Date: Thu Jun  5 06:20:05 2014
New Revision: 211255

URL: http://gcc.gnu.org/viewcvs?rev=211255&root=gcc&view=rev
Log:
	PR c/49706
	* doc/invoke.texi: Document -Wlogical-not-parentheses.
c-family/
	* c-common.c (warn_logical_not_parentheses): New function.
	* c-common.h (warn_logical_not_parentheses): Declare.
	* c.opt (Wlogical-not-parentheses): New option.
c/
	* c-typeck.c (parser_build_binary_op): Warn when logical not is used
	on the left hand side operand of a comparison. 
cp/
	* parser.c (cp_parser_binary_expression): Warn when logical not is
	used on the left hand side operand of a comparison.
testsuite/
	* c-c++-common/pr49706.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/pr49706.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/c-family/c-common.h
    trunk/gcc/c-family/c.opt
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/doc/invoke.texi
    trunk/gcc/testsuite/ChangeLog
Comment 6 Marek Polacek 2014-06-05 06:23:31 UTC
-Wlogical-not-parentheses is in, but I'm not marking this as fixed yet as we don't warn for #c2.  Maybe I will look at it, but unassigning for now.
Comment 7 Jakub Jelinek 2015-04-22 11:58:10 UTC
GCC 5.1 has been released.
Comment 8 Richard Biener 2015-07-16 09:11:07 UTC
GCC 5.2 is being released, adjusting target milestone to 5.3.
Comment 9 Richard Biener 2015-12-04 10:43:28 UTC
GCC 5.3 is being released, adjusting target milestone.
Comment 10 Richard Biener 2016-06-03 10:03:53 UTC
GCC 5.4 is being released, adjusting target milestone.
Comment 11 Eric Gallager 2019-08-18 04:11:47 UTC
(In reply to Marek Polacek from comment #6)
> -Wlogical-not-parentheses is in, but I'm not marking this as fixed yet as we
> don't warn for #c2.  Maybe I will look at it, but unassigning for now.

What flag should the case in comment 2 go under? -Wtype-limits? -Wbool-compare? -Wtautological-compare? Something else?