blob: 69c91cb15f47de21f10a3f9415b16641cb51edee [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
2// RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror -
Sebastian Redl9e1d29b2009-10-26 15:24:15 +00003
4// Test the various warnings under -Wparentheses
5void if_assign(void) {
6 int i;
Douglas Gregor827feec2010-01-08 00:20:23 +00007 if (i = 4) {} // expected-warning {{assignment as a condition}} \
8 // expected-note{{use '==' to turn this assignment into an equality comparison}}
Sebastian Redl9e1d29b2009-10-26 15:24:15 +00009 if ((i = 4)) {}
10}
11
12void bitwise_rel(unsigned i) {
Douglas Gregor827feec2010-01-08 00:20:23 +000013 (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}}
Sebastian Redl9e1d29b2009-10-26 15:24:15 +000019 (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}