Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s |
| 2 | // RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror - |
Sebastian Redl | 9e1d29b | 2009-10-26 15:24:15 +0000 | [diff] [blame] | 3 | |
| 4 | // Test the various warnings under -Wparentheses |
| 5 | void if_assign(void) { |
| 6 | int i; |
Douglas Gregor | 827feec | 2010-01-08 00:20:23 +0000 | [diff] [blame] | 7 | if (i = 4) {} // expected-warning {{assignment as a condition}} \ |
| 8 | // expected-note{{use '==' to turn this assignment into an equality comparison}} |
Sebastian Redl | 9e1d29b | 2009-10-26 15:24:15 +0000 | [diff] [blame] | 9 | if ((i = 4)) {} |
| 10 | } |
| 11 | |
| 12 | void bitwise_rel(unsigned i) { |
Douglas Gregor | 827feec | 2010-01-08 00:20:23 +0000 | [diff] [blame] | 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}} |
Sebastian Redl | 9e1d29b | 2009-10-26 15:24:15 +0000 | [diff] [blame] | 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 | } |