+2016-08-29 Marek Polacek <polacek@redhat.com>
+
+ PR c/77292
+ * c-common.c (warn_logical_not_parentheses): Don't warn for
+ a comparison or a logical operator.
+
2016-08-29 Tom de Vries <tom@codesourcery.com>
* c-common.c (build_va_arg): Fix type comparison assert.
/* Warn about logical not used on the left hand side operand of a comparison.
This function assumes that the LHS is inside of TRUTH_NOT_EXPR.
- Do not warn if RHS is of a boolean type. */
+ Do not warn if RHS is of a boolean type, a logical operator, or
+ a comparison. */
void
warn_logical_not_parentheses (location_t location, enum tree_code code,
{
if (TREE_CODE_CLASS (code) != tcc_comparison
|| TREE_TYPE (rhs) == NULL_TREE
- || TREE_CODE (TREE_TYPE (rhs)) == BOOLEAN_TYPE)
+ || TREE_CODE (TREE_TYPE (rhs)) == BOOLEAN_TYPE
+ || truth_value_p (TREE_CODE (rhs)))
return;
/* Don't warn for !x == 0 or !y != 0, those are equivalent to
+2016-08-29 Marek Polacek <polacek@redhat.com>
+
+ PR c/77292
+ * c-c++-common/Wlogical-not-parentheses-1.c: New test.
+
2016-08-29 Tom de Vries <tom@codesourcery.com>
PR c/77398
--- /dev/null
+/* PR c/77292 */
+/* { dg-do compile } */
+/* { dg-options "-Wlogical-not-parentheses" } */
+
+ /* Test that we don't warn if rhs is a comparison or a logical op. */
+
+int
+foo (int a, int b)
+{
+ int r = 0;
+ r += !a == (a < b);
+ r += !a == (a > b);
+ r += !a == (a >= b);
+ r += !a == (a <= b);
+ r += !a == (a != b);
+ r += !a == (a == b);
+ r += !a == (a || b);
+ r += !a == (a && b);
+ r += !a == (!b);
+
+ r += !a == (a ^ b); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r += !a == (a | b); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+ r += !a == (a & b); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
+
+ return r;
+}