PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.dg / Wparentheses-11.c
blob8858a7fb3f02ae5900f0d038cd2f19f99fe458de
1 /* PR 7543. Test operation of -Wparentheses. Precedence warnings.
2 !a | b and !a & b. */
3 /* { dg-do compile } */
4 /* { dg-options "-Wparentheses" } */
6 int foo (int);
8 int
9 bar (int a, int b, int c)
11 foo (!a & b); /* { dg-warning "parentheses" "correct warning" } */
12 foo (!a & (b < c));
13 foo (!a & (b > c));
14 foo (!a & (b == c));
15 foo (!a & (b != c));
16 foo (!a & (b <= c));
17 foo (!a & (b >= c));
18 foo (!a & (b && c));
19 foo (!a & (b || c));
20 foo (!a & !b);
21 foo (!(a & b));
22 foo ((!a) & b);
23 foo (!a & 2); /* { dg-warning "parentheses" "correct warning" } */
24 foo (!a & (2 < c));
25 foo (!a & (2 > c));
26 foo (!a & (2 == c));
27 foo (!a & (2 != c));
28 foo (!a & (2 <= c));
29 foo (!a & (2 >= c));
30 foo (!a & (2 && c));
31 foo (!a & (2 || c));
32 foo (!a & !2);
33 foo (!(a & 2));
34 foo ((!a) & 2);
35 foo (!1 & 2); /* { dg-warning "parentheses" "correct warning" } */
36 foo (!1 & (2 < c));
37 foo (!1 & (2 > c));
38 foo (!1 & (2 == c));
39 foo (!1 & (2 != c));
40 foo (!1 & (2 <= c));
41 foo (!1 & (2 >= c));
42 foo (!1 & (2 && c));
43 foo (!1 & (2 || c));
44 foo (!1 & !2);
45 foo (!(1 & 2));
47 foo (!a | b); /* { dg-warning "parentheses" "correct warning" } */
48 foo (!a | (b < c));
49 foo (!a | (b > c));
50 foo (!a | (b == c));
51 foo (!a | (b != c));
52 foo (!a | (b <= c));
53 foo (!a | (b >= c));
54 foo (!a | (b && c));
55 foo (!a | (b || c));
56 foo (!a | !b);
57 foo (!(a | b));
58 foo ((!a) | b);
59 foo (!a | 2); /* { dg-warning "parentheses" "correct warning" } */
60 foo (!a | (2 < c));
61 foo (!a | (2 > c));
62 foo (!a | (2 == c));
63 foo (!a | (2 != c));
64 foo (!a | (2 <= c));
65 foo (!a | (2 >= c));
66 foo (!a | (2 && c));
67 foo (!a | (2 || c));
68 foo (!a | !2);
69 foo (!(a | 2));
70 foo ((!a) | 2);
71 foo (!1 | 2); /* { dg-warning "parentheses" "correct warning" } */
72 foo (!1 | (2 < c));
73 foo (!1 | (2 > c));
74 foo (!1 | (2 == c));
75 foo (!1 | (2 != c));
76 foo (!1 | (2 <= c));
77 foo (!1 | (2 >= c));
78 foo (!1 | (2 && c));
79 foo (!1 | (2 || c));
80 foo (!1 | !2);
81 foo (!(1 | 2));
82 foo ((!1) | 2);
84 foo (b & !a); /* { dg-bogus "parentheses" "bogus warning" } */
85 foo ((b < c) & !a);
86 foo ((b > c) & !a);
87 foo ((b == c) & !a);
88 foo ((b != c) & !a);
89 foo ((b <= c) & !a);
90 foo ((b >= c) & !a);
91 foo ((b && c) & !a);
92 foo ((b || c) & !a);
93 foo (!b & !a);
94 foo (!(b & a));
95 foo (b & (!a));
96 foo (2 & !a); /* { dg-bogus "parentheses" "correct warning" } */
97 foo ((2 < c) & !a);
98 foo ((2 > c) & !a);
99 foo ((2 == c) & !a);
100 foo ((2 != c) & !a);
101 foo ((2 <= c) & !a);
102 foo ((2 >= c) & !a);
103 foo ((2 && c) & !a);
104 foo ((2 || c) & !a);
105 foo (!2 & !a);
106 foo (!(2 & a));
107 foo (2 & (!a));
108 foo (2 & !1); /* { dg-bogus "parentheses" "correct warning" } */
109 foo ((2 < c) & !1);
110 foo ((2 > c) & !1);
111 foo ((2 == c) & !1);
112 foo ((2 != c) & !1);
113 foo ((2 <= c) & !1);
114 foo ((2 >= c) & !1);
115 foo ((2 && c) & !1);
116 foo ((2 || c) & !1);
117 foo (!2 & !1);
118 foo (!(2 & 1));
120 foo (b | !a); /* { dg-bogus "parentheses" "correct warning" } */
121 foo ((b < c) | !a);
122 foo ((b > c) | !a);
123 foo ((b == c) | !a);
124 foo ((b != c) | !a);
125 foo ((b <= c) | !a);
126 foo ((b >= c) | !a);
127 foo ((b && c) | !a);
128 foo ((b || c) | !a);
129 foo (!b | !a);
130 foo (!(b | a));
131 foo (b | (!a));
132 foo (2 | !a); /* { dg-bogus "parentheses" "correct warning" } */
133 foo ((2 < c) | !a);
134 foo ((2 > c) | !a);
135 foo ((2 == c) | !a);
136 foo ((2 != c) | !a);
137 foo ((2 <= c) | !a);
138 foo ((2 >= c) | !a);
139 foo ((2 && c) | !a);
140 foo ((2 || c) | !a);
141 foo (!2 | !a);
142 foo (!(2 | a));
143 foo (2 | (!a));
144 foo (2 | !1); /* { dg-bogus "parentheses" "correct warning" } */
145 foo ((2 < c) | !1);
146 foo ((2 > c) | !1);
147 foo ((2 == c) | !1);
148 foo ((2 != c) | !1);
149 foo ((2 <= c) | !1);
150 foo ((2 >= c) | !1);
151 foo ((2 && c) | !1);
152 foo ((2 || c) | !1);
153 foo (!2 | !1);
154 foo (!(2 | 1));
155 foo (2 | (!1));
159 baz (int a, int b, int c)
161 foo (!a & (b << c));/* { dg-warning "parentheses" "correct warning" } */
162 foo (!a & (b >> c));/* { dg-warning "parentheses" "correct warning" } */
163 foo (!a & (b + c)); /* { dg-warning "parentheses" "correct warning" } */
164 foo (!a & (b - c)); /* { dg-warning "parentheses" "correct warning" } */
165 foo (!a & (b = c)); /* { dg-warning "parentheses" "correct warning" } */
166 foo (!a & ~b); /* { dg-warning "parentheses" "correct warning" } */
167 foo (!a & (b & c)); /* { dg-warning "parentheses" "correct warning" } */
168 foo (!a & (b | c)); /* { dg-warning "parentheses" "correct warning" } */
169 foo (!a & 2); /* { dg-warning "parentheses" "correct warning" } */
170 foo (!a & (2 << c));/* { dg-warning "parentheses" "correct warning" } */
171 foo (!a & (2 >> c));/* { dg-warning "parentheses" "correct warning" } */
172 foo (!a & (2 + c)); /* { dg-warning "parentheses" "correct warning" } */
173 foo (!a & (2 - c)); /* { dg-warning "parentheses" "correct warning" } */
174 foo (!a & (c = 2)); /* { dg-warning "parentheses" "correct warning" } */
175 foo (!a & ~2); /* { dg-warning "parentheses" "correct warning" } */
176 foo (!a & (2 & c)); /* { dg-warning "parentheses" "correct warning" } */
177 foo (!a & (2 | c)); /* { dg-warning "parentheses" "correct warning" } */
178 foo (!1 & (2 << c));/* { dg-warning "parentheses" "correct warning" } */
179 foo (!1 & (2 >> c));/* { dg-warning "parentheses" "correct warning" } */
180 foo (!1 & (2 + c)); /* { dg-warning "parentheses" "correct warning" } */
181 foo (!1 & (2 - c)); /* { dg-warning "parentheses" "correct warning" } */
182 foo (!1 & (c = 2)); /* { dg-warning "parentheses" "correct warning" } */
183 foo (!1 & ~2); /* { dg-warning "parentheses" "correct warning" } */
184 foo (!1 & (2 & c)); /* { dg-warning "parentheses" "correct warning" } */
185 foo (!1 & (2 | c)); /* { dg-warning "parentheses" "correct warning" } */
186 foo (!a | (b << c));/* { dg-warning "parentheses" "correct warning" } */
187 foo (!a | (b >> c));/* { dg-warning "parentheses" "correct warning" } */
188 foo (!a | (b + c)); /* { dg-warning "parentheses" "correct warning" } */
189 foo (!a | (b - c)); /* { dg-warning "parentheses" "correct warning" } */
190 foo (!a | (b = c)); /* { dg-warning "parentheses" "correct warning" } */
191 foo (!a | ~b); /* { dg-warning "parentheses" "correct warning" } */
192 foo (!a | (b & c)); /* { dg-warning "parentheses" "correct warning" } */
193 foo (!a | (b | c)); /* { dg-warning "parentheses" "correct warning" } */
194 foo (!a | (2 << c));/* { dg-warning "parentheses" "correct warning" } */
195 foo (!a | (2 >> c));/* { dg-warning "parentheses" "correct warning" } */
196 foo (!a | (2 + c)); /* { dg-warning "parentheses" "correct warning" } */
197 foo (!a | (2 - c)); /* { dg-warning "parentheses" "correct warning" } */
198 foo (!a | (c = 2)); /* { dg-warning "parentheses" "correct warning" } */
199 foo (!a | ~2); /* { dg-warning "parentheses" "correct warning" } */
200 foo (!a | (2 & c)); /* { dg-warning "parentheses" "correct warning" } */
201 foo (!a | (2 | c)); /* { dg-warning "parentheses" "correct warning" } */
202 foo (!1 | (2 << c));/* { dg-warning "parentheses" "correct warning" } */
203 foo (!1 | (2 >> c));/* { dg-warning "parentheses" "correct warning" } */
204 foo (!1 | (2 + c)); /* { dg-warning "parentheses" "correct warning" } */
205 foo (!1 | (2 - c)); /* { dg-warning "parentheses" "correct warning" } */
206 foo (!1 | (c = 2)); /* { dg-warning "parentheses" "correct warning" } */
207 foo (!1 | ~2); /* { dg-warning "parentheses" "correct warning" } */
208 foo (!1 | (2 & c)); /* { dg-warning "parentheses" "correct warning" } */
209 foo (!1 | (2 | c)); /* { dg-warning "parentheses" "correct warning" } */
210 foo ((b << c) & !a);
211 foo ((b >> c) & !a);
212 foo ((b + c) & !a);
213 foo ((b - c) & !a);
214 foo ((b = c) & !a);
215 foo (~b & !a);
216 foo ((b & c) & !a);
217 foo ((b | c) & !a);
218 foo ((2 << c) & !a);
219 foo ((2 >> c) & !a);
220 foo ((2 + c) & !a);
221 foo ((2 - c) & !a);
222 foo ((c = 2) & !a);
223 foo (~2 & !a);
224 foo ((2 & c) & !a);
225 foo ((2 | c) & !a);
226 foo ((2 << c) & !1);
227 foo ((2 >> c) & !1);
228 foo ((2 + c) & !1);
229 foo ((2 - c) & !1);
230 foo ((c = 2) & !1);
231 foo (~2 & !1);
232 foo ((2 & c) & !1);
233 foo ((2 | c) & !1);
234 foo ((b << c) | !a);
235 foo ((b >> c) | !a);
236 foo ((b + c) | !a);
237 foo ((b - c) | !a);
238 foo ((b = c) | !a);
239 foo (~b | !a);
240 foo ((b & c) | !a);
241 foo ((b | c) | !a);
242 foo ((2 << c) | !a);
243 foo ((2 >> c) | !a);
244 foo ((2 + c) | !a);
245 foo ((2 - c) | !a);
246 foo ((c = 2) | !a);
247 foo (~2 | !a);
248 foo ((2 & c) | !a);
249 foo ((2 | c) | !a);
250 foo ((2 << c) | !1);
251 foo ((2 >> c) | !1);
252 foo ((2 + c) | !1);
253 foo ((2 - c) | !1);
254 foo ((c = 2) | !1);
255 foo (~2 | !1);
256 foo ((2 & c) | !1);
257 foo ((2 | c) | !1);