John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value %s |
| 2 | |
| 3 | int i = 0; |
| 4 | int j = 0; |
| 5 | |
| 6 | void foo(); |
| 7 | |
| 8 | // PR4806 |
| 9 | void pr4806() { |
| 10 | 1,foo(); // expected-warning {{expression result unused}} |
| 11 | |
| 12 | // other |
| 13 | foo(); |
| 14 | i; // expected-warning {{expression result unused}} |
| 15 | |
| 16 | i,foo(); // expected-warning {{expression result unused}} |
| 17 | foo(),i; // expected-warning {{expression result unused}} |
| 18 | |
| 19 | i,j,foo(); // expected-warning {{expression result unused}} |
| 20 | i,foo(),j; // expected-warning {{expression result unused}} |
| 21 | foo(),i,j; // expected-warning {{expression result unused}} |
| 22 | |
| 23 | i++; |
| 24 | |
| 25 | i++,foo(); |
| 26 | foo(),i++; |
| 27 | |
| 28 | i++,j,foo(); // expected-warning {{expression result unused}} |
| 29 | i++,foo(),j; // expected-warning {{expression result unused}} |
| 30 | foo(),i++,j; // expected-warning {{expression result unused}} |
| 31 | |
| 32 | i,j++,foo(); // expected-warning {{expression result unused}} |
| 33 | i,foo(),j++; // expected-warning {{expression result unused}} |
| 34 | foo(),i,j++; // expected-warning {{expression result unused}} |
| 35 | |
| 36 | i++,j++,foo(); |
| 37 | i++,foo(),j++; |
| 38 | foo(),i++,j++; |
| 39 | |
| 40 | {}; |
| 41 | ({}); |
| 42 | ({}),foo(); |
| 43 | foo(),({}); |
| 44 | |
| 45 | (int)1U; // expected-warning {{expression result unused}} |
| 46 | (void)1U; |
| 47 | |
| 48 | // pointer to volatile has side effect (thus no warning) |
| 49 | int* pi = &i; |
| 50 | volatile int* pj = &j; |
| 51 | *pi; // expected-warning {{expression result unused}} |
| 52 | *pj; |
| 53 | } |
Ted Kremenek | c46a246 | 2010-04-07 18:49:21 +0000 | [diff] [blame] | 54 | |
| 55 | // Don't warn about unused '||', '&&' expressions that contain assignments. |
| 56 | int test_logical_foo1(); |
| 57 | int test_logical_foo2(); |
| 58 | int test_logical_foo3(); |
| 59 | int test_logical_bar() { |
| 60 | int x = 0; |
| 61 | (x = test_logical_foo1()) || // no-warning |
| 62 | (x = test_logical_foo2()) || // no-warning |
| 63 | (x = test_logical_foo3()); // no-warning |
| 64 | return x; |
| 65 | } |
| 66 | |