Argyrios Kyrtzidis | 355a9fe | 2010-09-19 21:21:25 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value -Wunused-label %s |
Ted Kremenek | e1fcf29 | 2010-04-08 17:54:28 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -verify -Wall %s |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 4 | |
| 5 | int i = 0; |
| 6 | int j = 0; |
| 7 | |
| 8 | void foo(); |
| 9 | |
| 10 | // PR4806 |
| 11 | void pr4806() { |
| 12 | 1,foo(); // expected-warning {{expression result unused}} |
| 13 | |
| 14 | // other |
| 15 | foo(); |
| 16 | i; // expected-warning {{expression result unused}} |
| 17 | |
| 18 | i,foo(); // expected-warning {{expression result unused}} |
| 19 | foo(),i; // expected-warning {{expression result unused}} |
| 20 | |
Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 21 | i,j,foo(); // expected-warning {{expression result unused}} expected-warning {{expression result unused}} |
| 22 | i,foo(),j; // expected-warning {{expression result unused}} expected-warning {{expression result unused}} |
| 23 | foo(),i,j; // expected-warning {{expression result unused}} expected-warning {{expression result unused}} |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 24 | |
| 25 | i++; |
| 26 | |
| 27 | i++,foo(); |
| 28 | foo(),i++; |
| 29 | |
| 30 | i++,j,foo(); // expected-warning {{expression result unused}} |
| 31 | i++,foo(),j; // expected-warning {{expression result unused}} |
| 32 | foo(),i++,j; // expected-warning {{expression result unused}} |
| 33 | |
| 34 | i,j++,foo(); // expected-warning {{expression result unused}} |
| 35 | i,foo(),j++; // expected-warning {{expression result unused}} |
| 36 | foo(),i,j++; // expected-warning {{expression result unused}} |
| 37 | |
| 38 | i++,j++,foo(); |
| 39 | i++,foo(),j++; |
| 40 | foo(),i++,j++; |
| 41 | |
| 42 | {}; |
| 43 | ({}); |
| 44 | ({}),foo(); |
| 45 | foo(),({}); |
| 46 | |
| 47 | (int)1U; // expected-warning {{expression result unused}} |
| 48 | (void)1U; |
| 49 | |
| 50 | // pointer to volatile has side effect (thus no warning) |
| 51 | int* pi = &i; |
| 52 | volatile int* pj = &j; |
| 53 | *pi; // expected-warning {{expression result unused}} |
| 54 | *pj; |
Argyrios Kyrtzidis | d2827af | 2010-09-19 21:21:10 +0000 | [diff] [blame] | 55 | |
Argyrios Kyrtzidis | 355a9fe | 2010-09-19 21:21:25 +0000 | [diff] [blame] | 56 | foo_label: // expected-warning {{unused label}} |
Argyrios Kyrtzidis | d2827af | 2010-09-19 21:21:10 +0000 | [diff] [blame] | 57 | i; // expected-warning {{expression result unused}} |
John McCall | 0faede6 | 2010-03-12 07:11:26 +0000 | [diff] [blame] | 58 | } |
Ted Kremenek | c46a246 | 2010-04-07 18:49:21 +0000 | [diff] [blame] | 59 | |
| 60 | // Don't warn about unused '||', '&&' expressions that contain assignments. |
| 61 | int test_logical_foo1(); |
| 62 | int test_logical_foo2(); |
| 63 | int test_logical_foo3(); |
| 64 | int test_logical_bar() { |
| 65 | int x = 0; |
| 66 | (x = test_logical_foo1()) || // no-warning |
| 67 | (x = test_logical_foo2()) || // no-warning |
| 68 | (x = test_logical_foo3()); // no-warning |
Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 69 | |
| 70 | x || test_logical_foo1(); // no-warning |
| 71 | |
Ted Kremenek | c46a246 | 2010-04-07 18:49:21 +0000 | [diff] [blame] | 72 | return x; |
| 73 | } |
| 74 | |
Ted Kremenek | fb7cb35 | 2011-03-01 20:34:48 +0000 | [diff] [blame] | 75 | // PR8282 |
| 76 | void conditional_for_control_flow(int cond, int x, int y) |
| 77 | { |
| 78 | cond? y++ : x; // no-warning |
| 79 | cond? y : ++x; // no-warning |
| 80 | cond? (x |= y) : ++x; // no-warning |
| 81 | cond? y : x; // expected-warning {{expression result unused}} |
| 82 | } |
| 83 | |
Argyrios Kyrtzidis | 2597345 | 2010-06-30 10:53:14 +0000 | [diff] [blame] | 84 | struct s0 { int f0; }; |
| 85 | |
| 86 | void f0(int a); |
| 87 | void f1(struct s0 *a) { |
| 88 | // rdar://8139785 |
| 89 | f0((int)(a->f0 + 1, 10)); // expected-warning {{expression result unused}} |
| 90 | } |