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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
  
     | 
    
      /* PR c/49706 */
/* { dg-do compile } */
/* { dg-options "-Wlogical-not-parentheses" } */
#ifndef __cplusplus
#define bool _Bool
#endif
enum E { A, B };
bool b;
extern enum E foo_e (void);
extern bool foo_b (void);
extern int foo_i (void);
#ifdef __cplusplus
template <class T, class U> bool tfn1(T t, U u) { return (!t == u); } /* { dg-warning "logical not is only applied to the left hand side of comparison" "" { target c++ } } */
template <class T, class U> bool tfn2(T t, U u) { return ((!t) == u); }
template <class T, class U> bool tfn3(T t, U u) { return (!g(t) == u); } /* { dg-warning "logical not is only applied to the left hand side of comparison" "" { target c++ } } */
template <class T, class U> bool tfn4(T t, U u) { return ((!g(t)) == u); }
template <class T, class U> bool tfn5(T t, U u) { return (!!t == u); } /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
template <class T, class U> bool tfn6(T t, U u) { return (!!g(t) == u); } /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
template <int N> bool tfn7(int i1, int i2) { return (!i1 == i2); } /* { dg-warning "logical not is only applied to the left hand side of comparison" "" { target c++ } } */
#endif
void
fn1 (int i1, int i2, bool b1, bool b2)
{
  b = !i1 == i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 != i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 < i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 > i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 <= i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 >= i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = i1 == i2;
  b = i1 != i2;
  b = i1 < i2;
  b = i1 > i2;
  b = i1 <= i2;
  b = i1 >= i2;
  /* Parens suppress the warning.  */
  b = (!i1) == i2;
  b = (!i1) != i2;
  b = (!i1) < i2;
  b = (!i1) > i2;
  b = (!i1) <= i2;
  b = (!i1) >= i2;
  /* ...but not these parens.  */
  b = (!i1 == i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 != i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 < i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 > i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 <= i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 >= i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !b1 == b2;
  b = !b1 != b2;
  b = !b1 < b2;
  b = !b1 > b2;
  b = !b1 <= b2;
  b = !b1 >= b2;
  b = !b1 == i2;
  b = !b1 != i2;
  b = !b1 < i2;
  b = !b1 > i2;
  b = !b1 <= i2;
  b = !b1 >= i2;
  b = !foo_i () == i1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!foo_i ()) == i1;
  b = !foo_b () == b1;
  b = !!i1 == i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
  b = !!i1 != i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
  b = !!i1 < i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
  b = !!i1 > i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
  b = !!i1 <= i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
  b = !!i1 >= i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
  b = !!foo_i () == i1; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
  b = !!b1 == i2;
  b = !!b1 != i2;
  b = !!b1 < i2;
  b = !!b1 > i2;
  b = !!b1 <= i2;
  b = !!b1 >= i2;
  /* Be careful here.  */
  b = (i1 == 0) != 0;
  b = (i1 == 0) == 0;
  b = (i1 != 0) != 0;
  b = (i1 != 0) == 0;
  b = !5 == 4; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !!5 == 4; /* { dg-bogus "logical not is only applied to the left hand side of comparison" "" { xfail *-*-* } } */
  b = !1 == 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !!1 == 1; /* { dg-bogus "logical not is only applied to the left hand side of comparison" "" { xfail *-*-* } } */
}
void
fn2 (enum E e)
{
  b = e == B;
  b = e == foo_e ();
  b = foo_e () == A;
  b = foo_e () == foo_e ();
  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;
  b = !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !(e == A);
  b = !(e == foo_e ());
  b = !(foo_e () == A);
  b = !(foo_e () == foo_e ());
  b = (!e) == A;
  b = (!e) == foo_e ();
  b = (!foo_e ()) == A;
  b = (!foo_e ()) == foo_e ();
}
void
fn3 (int i1, float f2)
{
  b = !i1 == f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 != f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 < f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 > f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 <= f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = !i1 >= f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = i1 == f2;
  b = i1 != f2;
  b = i1 < f2;
  b = i1 > f2;
  b = i1 <= f2;
  b = i1 >= f2;
  /* Parens suppress the warning.  */
  b = (!i1) == f2;
  b = (!i1) != f2;
  b = (!i1) < f2;
  b = (!i1) > f2;
  b = (!i1) <= f2;
  b = (!i1) >= f2;
  /* ...but not these parens.  */
  b = (!i1 == f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 != f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 < f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 > f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 <= f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
  b = (!i1 >= f2); /* { dg-warning "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" } */
  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" } */
  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" } */
  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 ();
}
 
     |