aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/Wlogical-not-parentheses-1.c
blob: b6b4e9d37c7ba8188cb3e7724bd465b4911de076 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* 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;
}