parentheses.c revision 827feec561c8a1f23c099da56c4ac98364ecfc09
1// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
2// RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror -
3
4// Test the various warnings under -Wparentheses
5void if_assign(void) {
6  int i;
7  if (i = 4) {} // expected-warning {{assignment as a condition}} \
8                // expected-note{{use '==' to turn this assignment into an equality comparison}}
9  if ((i = 4)) {}
10}
11
12void bitwise_rel(unsigned i) {
13  (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} \
14                        // expected-note{{place parentheses around the & expression to evaluate it first}}
15  (void)(0 == i & 0x2); // expected-warning {{& has lower precedence than ==}} \
16                        // expected-note{{place parentheses around the & expression to evaluate it first}}
17  (void)(i & 0xff < 30); // expected-warning {{& has lower precedence than <}} \
18                        // expected-note{{place parentheses around the & expression to evaluate it first}}
19  (void)((i & 0x2) == 0);
20  (void)(i & (0x2 == 0));
21  // Eager logical op
22  (void)(i == 1 | i == 2 | i == 3);
23  (void)(i != 1 & i != 2 & i != 3);
24}
25