diff options
author | John McCall <rjmccall@apple.com> | 2010-03-12 07:11:26 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-03-12 07:11:26 +0000 |
commit | 0faede6f31b07bcec7b776f2b420c3ea9bb3e58c (patch) | |
tree | b442f88dbe25c9f5e0a9666ff67a4ac152d01dac /test/Sema/warn-unused-value.c | |
parent | 617def321f362e010cc8ec0523b4f54157e5a7a5 (diff) |
Improve the unused-value check to look into comma expressions and filter out
voids in sub-expressions. Patch by Mike M!
Fixes PR4806.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98335 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Sema/warn-unused-value.c')
-rw-r--r-- | test/Sema/warn-unused-value.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/Sema/warn-unused-value.c b/test/Sema/warn-unused-value.c new file mode 100644 index 0000000000..2e0fa54eff --- /dev/null +++ b/test/Sema/warn-unused-value.c @@ -0,0 +1,53 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused-value %s + +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}} + + 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++; + + 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; +} |