+2015-03-10 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/65120
+ * c-common.c (warn_logical_not_parentheses): Don't warn for
+ !x == 0 or !x != 0.
+
2015-03-07 Marek Polacek <polacek@redhat.com>
PR sanitizer/65280
|| TREE_CODE (TREE_TYPE (rhs)) == BOOLEAN_TYPE)
return;
+ /* Don't warn for !x == 0 or !y != 0, those are equivalent to
+ !(x == 0) or !(y != 0). */
+ if ((code == EQ_EXPR || code == NE_EXPR)
+ && integer_zerop (rhs))
+ return;
+
warning_at (location, OPT_Wlogical_not_parentheses,
"logical not is only applied to the left hand side of "
"comparison");
+2015-03-10 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/65120
+ * c-typeck.c (parser_build_binary_op): Check for tcc_comparison
+ before preparing arguments to warn_logical_not_parentheses.
+
2015-03-09 Jakub Jelinek <jakub@redhat.com>
PR c/65120
code1, arg1.value, code2, arg2.value);
if (warn_logical_not_paren
+ && TREE_CODE_CLASS (code) == tcc_comparison
&& code1 == TRUTH_NOT_EXPR
&& code2 != TRUTH_NOT_EXPR
/* Avoid warning for !!x == y. */
+2015-03-10 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/65120
+ * parser.c (cp_parser_binary_expression): Check for tcc_comparison
+ before preparing arguments to warn_logical_not_parentheses.
+ Use maybe_constant_value on rhs.
+
2015-03-09 Jason Merrill <jason@redhat.com>
PR c++/65339
c_inhibit_evaluation_warnings -= current.lhs == truthvalue_true_node;
if (warn_logical_not_paren
+ && TREE_CODE_CLASS (current.tree_type) == tcc_comparison
&& current.lhs_type == TRUTH_NOT_EXPR
/* Avoid warning for !!x == y. */
&& (TREE_CODE (current.lhs) != NE_EXPR
&& (!DECL_P (current.lhs)
|| TREE_TYPE (current.lhs) == NULL_TREE
|| TREE_CODE (TREE_TYPE (current.lhs)) != BOOLEAN_TYPE))
- warn_logical_not_parentheses (current.loc, current.tree_type, rhs);
+ warn_logical_not_parentheses (current.loc, current.tree_type,
+ maybe_constant_value (rhs));
overload = NULL;
/* ??? Currently we pass lhs_type == ERROR_MARK and rhs_type ==
2015-03-10 Jakub Jelinek <jakub@redhat.com>
+ PR c/65120
+ * c-c++-common/pr49706.c (fn2): Don't expect warning if enumerator
+ on rhs is 0.
+ (fn4): New test.
+ * c-c++-common/pr65120.c: New test.
+
PR rtl-optimization/65321
* gcc.dg/pr65321.c: New test.
b = foo_e () == A;
b = foo_e () == foo_e ();
- b = !e == A; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ b = !e == A;
b = !e == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
- b = !foo_e () == A; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ b = !foo_e () == A;
b = !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
b = !(e == A);
b = !!i1 <= f2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
b = !!i1 >= f2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
}
+
+void
+fn4 (enum E e)
+{
+ b = e == A;
+ b = e == foo_e ();
+ b = foo_e () == B;
+ b = foo_e () == foo_e ();
+
+ b = !e == B; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ b = !e == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ b = !foo_e () == B; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ b = !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+
+ b = !(e == B);
+ b = !(e == foo_e ());
+ b = !(foo_e () == B);
+ b = !(foo_e () == foo_e ());
+
+ b = (!e) == B;
+ b = (!e) == foo_e ();
+ b = (!foo_e ()) == B;
+ b = (!foo_e ()) == foo_e ();
+}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Wlogical-not-parentheses" } */
+
+/* Test that we don't warn if rhs is 0 and comparison is == or !=. */
+
+#ifndef __cplusplus
+#define bool _Bool
+#endif
+
+bool r;
+
+int
+f1 (int a)
+{
+ r = !a == 0;
+ r = !a != 0;
+ r = !a == 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r = !a != 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+}
+
+int
+f2 (int a)
+{
+ r = !a > 0; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r = !a >= 0; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r = !a < 0; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r = !a <= 0; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r = !a > 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r = !a >= 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r = !a < 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r = !a <= 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+}