summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/pr65120.c
blob: c9c1f5f7e659a4dfeebc2c3878cabd96da0107d5 (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
27
28
29
30
31
32
/* { 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" } */
}