2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / gcc / testsuite / c-c++-common / pr49706.c
blob615f3e40a48553dce2d4908704447c2e00bc412d
1 /* PR c/49706 */
2 /* { dg-do compile } */
3 /* { dg-options "-Wlogical-not-parentheses" } */
5 #ifndef __cplusplus
6 #define bool _Bool
7 #endif
8 enum E { A, B };
9 bool b;
10 extern enum E foo_e (void);
11 extern bool foo_b (void);
12 extern int foo_i (void);
14 #ifdef __cplusplus
15 template <class T, class U> bool f1(T t, U u) { return (!t == u); } /* { dg-warning "logical not is only applied to the left hand side of comparison" "" { target c++ } 15 } */
16 template <class T, class U> bool f2(T t, U u) { return ((!t) == u); }
17 template <class T, class U> bool f3(T t, U u) { return (!g(t) == u); } /* { dg-warning "logical not is only applied to the left hand side of comparison" "" { target c++ } 17 } */
18 template <class T, class U> bool f4(T t, U u) { return ((!g(t)) == u); }
19 #endif
21 void
22 fn1 (int i1, int i2, bool b1, bool b2)
24 b = !i1 == i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
25 b = !i1 != i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
26 b = !i1 < i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
27 b = !i1 > i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
28 b = !i1 <= i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
29 b = !i1 >= i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
31 b = i1 == i2;
32 b = i1 != i2;
33 b = i1 < i2;
34 b = i1 > i2;
35 b = i1 <= i2;
36 b = i1 >= i2;
38 /* Parens suppress the warning. */
39 b = (!i1) == i2;
40 b = (!i1) != i2;
41 b = (!i1) < i2;
42 b = (!i1) > i2;
43 b = (!i1) <= i2;
44 b = (!i1) >= i2;
46 /* ...but not these parens. */
47 b = (!i1 == i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
48 b = (!i1 != i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
49 b = (!i1 < i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
50 b = (!i1 > i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
51 b = (!i1 <= i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
52 b = (!i1 >= i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
54 b = !b1 == b2;
55 b = !b1 != b2;
56 b = !b1 < b2;
57 b = !b1 > b2;
58 b = !b1 <= b2;
59 b = !b1 >= b2;
61 b = !foo_i () == i1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
62 b = (!foo_i ()) == i1;
63 b = !foo_b () == b1;
65 b = !!i1 == i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
66 b = !!i1 != i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
67 b = !!i1 < i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
68 b = !!i1 > i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
69 b = !!i1 <= i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
70 b = !!i1 >= i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
71 b = !!foo_i () == i1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
73 /* Be careful here. */
74 b = (i1 == 0) != 0;
75 b = (i1 == 0) == 0;
76 b = (i1 != 0) != 0;
77 b = (i1 != 0) == 0;
80 void
81 fn2 (enum E e)
83 b = e == B;
84 b = e == foo_e ();
85 b = foo_e () == A;
86 b = foo_e () == foo_e ();
88 b = !e == A; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
89 b = !e == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
90 b = !foo_e () == A; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
91 b = !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
93 b = !(e == A);
94 b = !(e == foo_e ());
95 b = !(foo_e () == A);
96 b = !(foo_e () == foo_e ());
98 b = (!e) == A;
99 b = (!e) == foo_e ();
100 b = (!foo_e ()) == A;
101 b = (!foo_e ()) == foo_e ();