2010-03-12 15:11:26 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value %s
|
2010-04-09 01:54:28 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
|
2010-03-12 15:11:26 +08:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
void foo();
|
|
|
|
|
|
|
|
// PR4806
|
|
|
|
void pr4806() {
|
|
|
|
1,foo(); // expected-warning {{expression result unused}}
|
|
|
|
|
|
|
|
// other
|
|
|
|
foo();
|
|
|
|
i; // expected-warning {{expression result unused}}
|
|
|
|
|
|
|
|
i,foo(); // expected-warning {{expression result unused}}
|
|
|
|
foo(),i; // expected-warning {{expression result unused}}
|
|
|
|
|
2010-06-30 18:53:14 +08:00
|
|
|
i,j,foo(); // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
|
|
|
|
i,foo(),j; // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
|
|
|
|
foo(),i,j; // expected-warning {{expression result unused}} expected-warning {{expression result unused}}
|
2010-03-12 15:11:26 +08:00
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
i++,foo();
|
|
|
|
foo(),i++;
|
|
|
|
|
|
|
|
i++,j,foo(); // expected-warning {{expression result unused}}
|
|
|
|
i++,foo(),j; // expected-warning {{expression result unused}}
|
|
|
|
foo(),i++,j; // expected-warning {{expression result unused}}
|
|
|
|
|
|
|
|
i,j++,foo(); // expected-warning {{expression result unused}}
|
|
|
|
i,foo(),j++; // expected-warning {{expression result unused}}
|
|
|
|
foo(),i,j++; // expected-warning {{expression result unused}}
|
|
|
|
|
|
|
|
i++,j++,foo();
|
|
|
|
i++,foo(),j++;
|
|
|
|
foo(),i++,j++;
|
|
|
|
|
|
|
|
{};
|
|
|
|
({});
|
|
|
|
({}),foo();
|
|
|
|
foo(),({});
|
|
|
|
|
|
|
|
(int)1U; // expected-warning {{expression result unused}}
|
|
|
|
(void)1U;
|
|
|
|
|
|
|
|
// pointer to volatile has side effect (thus no warning)
|
|
|
|
int* pi = &i;
|
|
|
|
volatile int* pj = &j;
|
|
|
|
*pi; // expected-warning {{expression result unused}}
|
|
|
|
*pj;
|
|
|
|
}
|
2010-04-08 02:49:21 +08:00
|
|
|
|
|
|
|
// Don't warn about unused '||', '&&' expressions that contain assignments.
|
|
|
|
int test_logical_foo1();
|
|
|
|
int test_logical_foo2();
|
|
|
|
int test_logical_foo3();
|
|
|
|
int test_logical_bar() {
|
|
|
|
int x = 0;
|
|
|
|
(x = test_logical_foo1()) || // no-warning
|
|
|
|
(x = test_logical_foo2()) || // no-warning
|
|
|
|
(x = test_logical_foo3()); // no-warning
|
2010-06-30 18:53:14 +08:00
|
|
|
|
|
|
|
x || test_logical_foo1(); // no-warning
|
|
|
|
|
2010-04-08 02:49:21 +08:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2010-06-30 18:53:14 +08:00
|
|
|
struct s0 { int f0; };
|
|
|
|
|
|
|
|
void f0(int a);
|
|
|
|
void f1(struct s0 *a) {
|
|
|
|
// rdar://8139785
|
|
|
|
f0((int)(a->f0 + 1, 10)); // expected-warning {{expression result unused}}
|
|
|
|
}
|