diff options
| author | Matt Beaumont-Gay <matthewbg@google.com> | 2013-01-17 02:06:08 +0000 |
|---|---|---|
| committer | Matt Beaumont-Gay <matthewbg@google.com> | 2013-01-17 02:06:08 +0000 |
| commit | 978cca9f49a1c0e3a01096017c9a34726866fbf3 (patch) | |
| tree | c513b2ae6119b9ecbee691724a4a93d2479319e2 /clang/test/Sema/unused-expr.c | |
| parent | eaa75a69ad5d7e2279b58d9c2b6fc4aea35b1aa1 (diff) | |
| download | bcm5719-llvm-978cca9f49a1c0e3a01096017c9a34726866fbf3.tar.gz bcm5719-llvm-978cca9f49a1c0e3a01096017c9a34726866fbf3.zip | |
Suppress all -Wunused-value warnings from macro body expansions.
This is inspired by a number of false positives in real code, including
PR14968. I've added test cases reduced from these false positives to
test/Sema/unused-expr.c, as well as corresponding test cases that pass the
offending expressions as arguments to a no-op macro to ensure that we do warn
there.
This also removes my previous tweak from r166522/r166534, so that we warn on
unused cast expressions in macro arguments.
There were several test cases that were using -Wunused-value to test general
diagnostic emission features; I changed those to use other warnings or warn on
a macro argument expression. I stared at the test case for PR14399 for a while
with Richard Smith and we believe the new test case exercises the same
codepaths as before.
llvm-svn: 172696
Diffstat (limited to 'clang/test/Sema/unused-expr.c')
| -rw-r--r-- | clang/test/Sema/unused-expr.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/clang/test/Sema/unused-expr.c b/clang/test/Sema/unused-expr.c index aa81febdbbd..0786ede6763 100644 --- a/clang/test/Sema/unused-expr.c +++ b/clang/test/Sema/unused-expr.c @@ -123,13 +123,30 @@ void f(int i, ...) { // PR8371 int fn5() __attribute__ ((__const)); -// OpenSSL has some macros like this; we shouldn't warn on the cast. +// Don't warn for unused expressions in macro bodies; however, do warn for +// unused expressions in macro arguments. Macros below are reduced from code +// found in the wild. +#define NOP(a) (a) #define M1(a, b) (long)foo((a), (b)) -// But, we should still warn on other subexpressions of casts in macros. #define M2 (long)0; +#define M3(a) (t3(a), fn2()) +#define M4(a, b) (foo((a), (b)) ? 0 : t3(a), 1) +#define M5(a, b) (foo((a), (b)), 1) void t11(int i, int j) { M1(i, j); // no warning - M2; // expected-warning {{expression result unused}} + NOP((long)foo(i, j)); // expected-warning {{expression result unused}} + M2; // no warning + NOP((long)0); // expected-warning {{expression result unused}} + M3(i); // no warning + NOP((t3(i), fn2())); // expected-warning {{ignoring return value}} + M4(i, j); // no warning + NOP((foo(i, j) ? 0 : t3(i), 1)); // expected-warning {{expression result unused}} + M5(i, j); // no warning + NOP((foo(i, j), 1)); // expected-warning {{expression result unused}} } +#undef NOP #undef M1 #undef M2 +#undef M3 +#undef M4 +#undef M5 |

