Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -Wparentheses -fsyntax-only -verify %s |
Sebastian Redl | aee3c93 | 2009-10-27 12:10:02 +0000 | [diff] [blame] | 2 | // RUN: clang-cc -Wparentheses -fixit %s -o - | clang-cc -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; |
| 7 | if (i = 4) {} // expected-warning {{assignment as a condition}} |
| 8 | if ((i = 4)) {} |
| 9 | } |
| 10 | |
| 11 | void bitwise_rel(unsigned i) { |
| 12 | (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} |
| 13 | (void)(0 == i & 0x2); // expected-warning {{& has lower precedence than ==}} |
| 14 | (void)(i & 0xff < 30); // expected-warning {{& has lower precedence than <}} |
| 15 | (void)((i & 0x2) == 0); |
| 16 | (void)(i & (0x2 == 0)); |
| 17 | // Eager logical op |
| 18 | (void)(i == 1 | i == 2 | i == 3); |
| 19 | (void)(i != 1 & i != 2 & i != 3); |
| 20 | } |