diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2013-09-10 03:05:56 +0000 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2013-09-10 03:05:56 +0000 |
| commit | 5ef21758665b9d6f0a481f712a19407dd41af706 (patch) | |
| tree | c897177b80473c0a33500ec85e0ba8a39defd89e /clang/test/SemaCXX/warn-unused-filescoped.cpp | |
| parent | df0ae22f92ea1c371640fa9d2b5d461e7b38207f (diff) | |
| download | bcm5719-llvm-5ef21758665b9d6f0a481f712a19407dd41af706.tar.gz bcm5719-llvm-5ef21758665b9d6f0a481f712a19407dd41af706.zip | |
Make -Wunused warning rules more consistent.
This patch does a few different things.
This patch improves unused var diags for const vars: we no longer
unconditionally suppress diagnostics for const vars, instead only suppressing
the diagnostic when the declaration appears to be useful.
This patch also makes us more consistently use whether a variable/function
is declared in the main file to suppress diagnostics where appropriate.
Fixes <rdar://problem/14907887>.
llvm-svn: 190382
Diffstat (limited to 'clang/test/SemaCXX/warn-unused-filescoped.cpp')
| -rw-r--r-- | clang/test/SemaCXX/warn-unused-filescoped.cpp | 66 |
1 files changed, 42 insertions, 24 deletions
diff --git a/clang/test/SemaCXX/warn-unused-filescoped.cpp b/clang/test/SemaCXX/warn-unused-filescoped.cpp index 9fb601130d3..aa2b2e5103c 100644 --- a/clang/test/SemaCXX/warn-unused-filescoped.cpp +++ b/clang/test/SemaCXX/warn-unused-filescoped.cpp @@ -1,6 +1,41 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -Wno-c++11-extensions -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function -std=c++11 %s +#ifdef HEADER + +static void headerstatic() {} // expected-warning{{unused}} +static inline void headerstaticinline() {} + +namespace { + void headeranon() {} // expected-warning{{unused}} + inline void headerinlineanon() {} +} + +namespace test7 +{ + template<typename T> + static inline void foo(T) { } + + // This should not emit an unused-function warning since it inherits + // the static storage type from the base template. + template<> + inline void foo(int) { } + + // Partial specialization + template<typename T, typename U> + static inline void bar(T, U) { } + + template<typename U> + inline void bar(int, U) { } + + template<> + inline void bar(int, int) { } +}; + +#else +#define HEADER +#include "warn-unused-filescoped.cpp" + static void f1(); // expected-warning{{unused}} namespace { @@ -37,8 +72,10 @@ namespace { void S::m3() { } // expected-warning{{unused}} -static inline void f4() { } -const unsigned int cx = 0; +static inline void f4() { } // expected-warning{{unused}} +const unsigned int cx = 0; // expected-warning{{unused}} +const unsigned int cy = 0; +int f5() { return cy; } static int x1; // expected-warning{{unused}} @@ -98,7 +135,7 @@ namespace test5 { // FIXME: We should produce warnings for both of these. static const int m = n; int x = sizeof(m); - static const double d = 0.0; + static const double d = 0.0; // expected-warning{{not needed and will not be emitted}} int y = sizeof(d); } @@ -133,27 +170,6 @@ namespace test6 { }; } -namespace test7 -{ - template<typename T> - static inline void foo(T) { } - - // This should not emit an unused-function warning since it inherits - // the static storage type from the base template. - template<> - inline void foo(int) { } - - // Partial specialization - template<typename T, typename U> - static inline void bar(T, U) { } - - template<typename U> - inline void bar(int, U) { } - - template<> - inline void bar(int, int) { } -}; - namespace pr14776 { namespace { struct X {}; @@ -161,3 +177,5 @@ namespace pr14776 { X a = X(); // expected-warning {{unused variable 'a'}} auto b = X(); // expected-warning {{unused variable 'b'}} } + +#endif |

