annotate gcc/testsuite/c-c++-common/pr49706.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* PR c/49706 */
kono
parents:
diff changeset
2 /* { dg-do compile } */
kono
parents:
diff changeset
3 /* { dg-options "-Wlogical-not-parentheses" } */
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 #ifndef __cplusplus
kono
parents:
diff changeset
6 #define bool _Bool
kono
parents:
diff changeset
7 #endif
kono
parents:
diff changeset
8 enum E { A, B };
kono
parents:
diff changeset
9 bool b;
kono
parents:
diff changeset
10 extern enum E foo_e (void);
kono
parents:
diff changeset
11 extern bool foo_b (void);
kono
parents:
diff changeset
12 extern int foo_i (void);
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 #ifdef __cplusplus
kono
parents:
diff changeset
15 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++ } } */
kono
parents:
diff changeset
16 template <class T, class U> bool tfn2(T t, U u) { return ((!t) == u); }
kono
parents:
diff changeset
17 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++ } } */
kono
parents:
diff changeset
18 template <class T, class U> bool tfn4(T t, U u) { return ((!g(t)) == u); }
kono
parents:
diff changeset
19 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" } */
kono
parents:
diff changeset
20 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" } */
kono
parents:
diff changeset
21 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++ } } */
kono
parents:
diff changeset
22 #endif
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 void
kono
parents:
diff changeset
25 fn1 (int i1, int i2, bool b1, bool b2)
kono
parents:
diff changeset
26 {
kono
parents:
diff changeset
27 b = !i1 == i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
28 b = !i1 != i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
29 b = !i1 < i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
30 b = !i1 > i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
31 b = !i1 <= i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
32 b = !i1 >= i2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 b = i1 == i2;
kono
parents:
diff changeset
35 b = i1 != i2;
kono
parents:
diff changeset
36 b = i1 < i2;
kono
parents:
diff changeset
37 b = i1 > i2;
kono
parents:
diff changeset
38 b = i1 <= i2;
kono
parents:
diff changeset
39 b = i1 >= i2;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 /* Parens suppress the warning. */
kono
parents:
diff changeset
42 b = (!i1) == i2;
kono
parents:
diff changeset
43 b = (!i1) != i2;
kono
parents:
diff changeset
44 b = (!i1) < i2;
kono
parents:
diff changeset
45 b = (!i1) > i2;
kono
parents:
diff changeset
46 b = (!i1) <= i2;
kono
parents:
diff changeset
47 b = (!i1) >= i2;
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 /* ...but not these parens. */
kono
parents:
diff changeset
50 b = (!i1 == i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
51 b = (!i1 != i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
52 b = (!i1 < i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
53 b = (!i1 > i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
54 b = (!i1 <= i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
55 b = (!i1 >= i2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 b = !b1 == b2;
kono
parents:
diff changeset
58 b = !b1 != b2;
kono
parents:
diff changeset
59 b = !b1 < b2;
kono
parents:
diff changeset
60 b = !b1 > b2;
kono
parents:
diff changeset
61 b = !b1 <= b2;
kono
parents:
diff changeset
62 b = !b1 >= b2;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 b = !b1 == i2;
kono
parents:
diff changeset
65 b = !b1 != i2;
kono
parents:
diff changeset
66 b = !b1 < i2;
kono
parents:
diff changeset
67 b = !b1 > i2;
kono
parents:
diff changeset
68 b = !b1 <= i2;
kono
parents:
diff changeset
69 b = !b1 >= i2;
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 b = !foo_i () == i1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
72 b = (!foo_i ()) == i1;
kono
parents:
diff changeset
73 b = !foo_b () == b1;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 b = !!i1 == i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
76 b = !!i1 != i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
77 b = !!i1 < i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
78 b = !!i1 > i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
79 b = !!i1 <= i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
80 b = !!i1 >= i2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
81 b = !!foo_i () == i1; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 b = !!b1 == i2;
kono
parents:
diff changeset
84 b = !!b1 != i2;
kono
parents:
diff changeset
85 b = !!b1 < i2;
kono
parents:
diff changeset
86 b = !!b1 > i2;
kono
parents:
diff changeset
87 b = !!b1 <= i2;
kono
parents:
diff changeset
88 b = !!b1 >= i2;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 /* Be careful here. */
kono
parents:
diff changeset
91 b = (i1 == 0) != 0;
kono
parents:
diff changeset
92 b = (i1 == 0) == 0;
kono
parents:
diff changeset
93 b = (i1 != 0) != 0;
kono
parents:
diff changeset
94 b = (i1 != 0) == 0;
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 b = !5 == 4; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
97 b = !!5 == 4; /* { dg-bogus "logical not is only applied to the left hand side of comparison" "" { xfail *-*-* } } */
kono
parents:
diff changeset
98 b = !1 == 1; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
99 b = !!1 == 1; /* { dg-bogus "logical not is only applied to the left hand side of comparison" "" { xfail *-*-* } } */
kono
parents:
diff changeset
100 }
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 void
kono
parents:
diff changeset
103 fn2 (enum E e)
kono
parents:
diff changeset
104 {
kono
parents:
diff changeset
105 b = e == B;
kono
parents:
diff changeset
106 b = e == foo_e ();
kono
parents:
diff changeset
107 b = foo_e () == A;
kono
parents:
diff changeset
108 b = foo_e () == foo_e ();
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 b = !e == A;
kono
parents:
diff changeset
111 b = !e == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
112 b = !foo_e () == A;
kono
parents:
diff changeset
113 b = !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 b = !(e == A);
kono
parents:
diff changeset
116 b = !(e == foo_e ());
kono
parents:
diff changeset
117 b = !(foo_e () == A);
kono
parents:
diff changeset
118 b = !(foo_e () == foo_e ());
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 b = (!e) == A;
kono
parents:
diff changeset
121 b = (!e) == foo_e ();
kono
parents:
diff changeset
122 b = (!foo_e ()) == A;
kono
parents:
diff changeset
123 b = (!foo_e ()) == foo_e ();
kono
parents:
diff changeset
124 }
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 void
kono
parents:
diff changeset
127 fn3 (int i1, float f2)
kono
parents:
diff changeset
128 {
kono
parents:
diff changeset
129 b = !i1 == f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
130 b = !i1 != f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
131 b = !i1 < f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
132 b = !i1 > f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
133 b = !i1 <= f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
134 b = !i1 >= f2; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 b = i1 == f2;
kono
parents:
diff changeset
137 b = i1 != f2;
kono
parents:
diff changeset
138 b = i1 < f2;
kono
parents:
diff changeset
139 b = i1 > f2;
kono
parents:
diff changeset
140 b = i1 <= f2;
kono
parents:
diff changeset
141 b = i1 >= f2;
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 /* Parens suppress the warning. */
kono
parents:
diff changeset
144 b = (!i1) == f2;
kono
parents:
diff changeset
145 b = (!i1) != f2;
kono
parents:
diff changeset
146 b = (!i1) < f2;
kono
parents:
diff changeset
147 b = (!i1) > f2;
kono
parents:
diff changeset
148 b = (!i1) <= f2;
kono
parents:
diff changeset
149 b = (!i1) >= f2;
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 /* ...but not these parens. */
kono
parents:
diff changeset
152 b = (!i1 == f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
153 b = (!i1 != f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
154 b = (!i1 < f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
155 b = (!i1 > f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
156 b = (!i1 <= f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
157 b = (!i1 >= f2); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 b = !!i1 == f2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
160 b = !!i1 != f2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
161 b = !!i1 < f2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
162 b = !!i1 > f2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
163 b = !!i1 <= f2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
164 b = !!i1 >= f2; /* { dg-bogus "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
165 }
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 void
kono
parents:
diff changeset
168 fn4 (enum E e)
kono
parents:
diff changeset
169 {
kono
parents:
diff changeset
170 b = e == A;
kono
parents:
diff changeset
171 b = e == foo_e ();
kono
parents:
diff changeset
172 b = foo_e () == B;
kono
parents:
diff changeset
173 b = foo_e () == foo_e ();
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 b = !e == B; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
176 b = !e == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
177 b = !foo_e () == B; /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
178 b = !foo_e () == foo_e (); /* { dg-warning "logical not is only applied to the left hand side of comparison" } */
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 b = !(e == B);
kono
parents:
diff changeset
181 b = !(e == foo_e ());
kono
parents:
diff changeset
182 b = !(foo_e () == B);
kono
parents:
diff changeset
183 b = !(foo_e () == foo_e ());
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 b = (!e) == B;
kono
parents:
diff changeset
186 b = (!e) == foo_e ();
kono
parents:
diff changeset
187 b = (!foo_e ()) == B;
kono
parents:
diff changeset
188 b = (!foo_e ()) == foo_e ();
kono
parents:
diff changeset
189 }