Author: Bruno Ricci Date: 2020-07-26T17:20:56+01:00 New Revision: a2f83d5a07daf7a9b717fff8916c44cd7cc1c678
URL: https://github.com/llvm/llvm-project/commit/a2f83d5a07daf7a9b717fff8916c44cd7cc1c678 DIFF: https://github.com/llvm/llvm-project/commit/a2f83d5a07daf7a9b717fff8916c44cd7cc1c678.diff LOG: [clang][NFC] Add tests for the use of NamedDecl::getDeclName in the unused/unneeded diagnostics. Added: Modified: clang/test/SemaCXX/warn-func-not-needed.cpp clang/test/SemaCXX/warn-member-not-needed.cpp clang/test/SemaCXX/warn-unused-filescoped.cpp clang/test/SemaCXX/warn-variable-not-needed.cpp Removed: ################################################################################ diff --git a/clang/test/SemaCXX/warn-func-not-needed.cpp b/clang/test/SemaCXX/warn-func-not-needed.cpp index 65721f44f570..5040aaad9460 100644 --- a/clang/test/SemaCXX/warn-func-not-needed.cpp +++ b/clang/test/SemaCXX/warn-func-not-needed.cpp @@ -1,13 +1,23 @@ // RUN: %clang_cc1 -fsyntax-only -verify -Wall %s namespace test1 { - static void f() {} // expected-warning {{is not needed and will not be emitted}} - static void f(); - template <typename T> - void foo() { - f(); - } +static void f() {} // expected-warning {{function 'f' is not needed and will not be emitted}} +static void f(); +template <typename T> +void foo() { + f(); +} +} + +namespace test1_template { +template <typename T> static void f() {} +template <> void f<int>() {} // expected-warning {{function 'f' is not needed and will not be emitted}} +template <typename T> +void foo() { + f<int>(); + f<long>(); } +} // namespace test1_template namespace test2 { static void f() {} diff --git a/clang/test/SemaCXX/warn-member-not-needed.cpp b/clang/test/SemaCXX/warn-member-not-needed.cpp index 61bb3488c611..95241f4f7fee 100644 --- a/clang/test/SemaCXX/warn-member-not-needed.cpp +++ b/clang/test/SemaCXX/warn-member-not-needed.cpp @@ -1,11 +1,19 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wunneeded-member-function %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunneeded-member-function -Wno-unused-template %s namespace { class A { - void g() {} // expected-warning {{is not needed and will not be emitted}} + void g() {} // expected-warning {{member function 'g' is not needed and will not be emitted}} + template <typename T> void gt(T) {} + template <> void gt<int>(int) {} // expected-warning {{member function 'gt' is not needed and will not be emitted}} + template <> void gt(float) {} // expected-warning {{member function 'gt' is not needed and will not be emitted}} + template <typename T> void foo() { g(); + gt(0); + gt(0.0f); + gt(0.0); } }; + template void A::gt(double); // no-warning } diff --git a/clang/test/SemaCXX/warn-unused-filescoped.cpp b/clang/test/SemaCXX/warn-unused-filescoped.cpp index 7ea398feb2b1..056543d5eeb0 100644 --- a/clang/test/SemaCXX/warn-unused-filescoped.cpp +++ b/clang/test/SemaCXX/warn-unused-filescoped.cpp @@ -1,14 +1,15 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions -std=c++98 %s +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs \ +// RUN: -Wno-c++11-extensions -Wno-c++14-extensions -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template -Wunused-member-function -Wno-unused-local-typedefs -std=c++14 %s #ifdef HEADER -static void headerstatic() {} // expected-warning{{unused}} +static void headerstatic() {} // expected-warning{{unused function 'headerstatic'}} static inline void headerstaticinline() {} namespace { - void headeranon() {} // expected-warning{{unused}} - inline void headerinlineanon() {} +void headeranon() {} // expected-warning{{unused function 'headeranon'}} +inline void headerinlineanon() {} } namespace test7 @@ -43,31 +44,31 @@ namespace pr19713 { #define HEADER #include "warn-unused-filescoped.cpp" -static void f1(); // expected-warning{{unused}} +static void f1(); // expected-warning{{unused function 'f1'}} namespace { - void f2(); // expected-warning{{unused}} +void f2(); // expected-warning{{unused function 'f2'}} - void f3() { } // expected-warning{{unused}} +void f3() {} // expected-warning{{unused function 'f3'}} - struct S { - void m1() { } // expected-warning{{unused}} - void m2(); // expected-warning{{unused}} - void m3(); - S(const S&); - void operator=(const S&); - }; +struct S { + void m1() {} // expected-warning{{unused member function 'm1'}} + void m2(); // expected-warning{{unused member function 'm2'}} + void m3(); + S(const S &); + void operator=(const S &); +}; template <typename T> struct TS { void m(); }; - template <> void TS<int>::m() { } // expected-warning{{unused}} + template <> void TS<int>::m() {} // expected-warning{{unused member function 'm'}} template <typename T> - void tf() { } // expected-warning{{unused}} - template <> void tf<int>() { } // expected-warning{{unused}} - + void tf() {} // expected-warning{{unused function template 'tf'}} + template <> void tf<int>() {} // expected-warning{{unused function 'tf'}} + struct VS { virtual void vm() { } }; @@ -77,27 +78,31 @@ namespace { }; } -void S::m3() { } // expected-warning{{unused}} +void S::m3() {} // expected-warning{{unused member function 'm3'}} -static inline void f4() { } // expected-warning{{unused}} -const unsigned int cx = 0; // expected-warning{{unused}} +static inline void f4() {} // expected-warning{{unused function 'f4'}} +const unsigned int cx = 0; // expected-warning{{unused variable 'cx'}} const unsigned int cy = 0; int f5() { return cy; } -static int x1; // expected-warning{{unused}} +static int x1; // expected-warning{{unused variable 'x1'}} namespace { - int x2; // expected-warning{{unused}} - - struct S2 { - static int x; // expected-warning{{unused}} - }; +int x2; // expected-warning{{unused variable 'x2'}} + +struct S2 { + static int x; // expected-warning{{unused variable 'x'}} +}; template <typename T> struct TS2 { static int x; }; - template <> int TS2<int>::x; // expected-warning{{unused}} + template <> int TS2<int>::x; // expected-warning{{unused variable 'x'}} + + template <typename T, typename U> int vt = 0; // expected-warning {{unused variable template 'vt'}} + template <typename T> int vt<T, void> = 0; + template <> int vt<void, void> = 0; // expected-warning {{unused variable 'vt'}} } namespace PR8841 { @@ -120,17 +125,21 @@ namespace PR8841 { namespace test4 { namespace { struct A {}; } - void test(A a); // expected-warning {{unused function}} + void test(A a); // expected-warning {{unused function 'test'}} extern "C" void test4(A a); } namespace rdar8733476 { - static void foo() { } // expected-warning {{not needed and will not be emitted}} +static void foo() {} // expected-warning {{function 'foo' is not needed and will not be emitted}} +template <typename T> static void foo_t() {} // expected-warning {{unused function template 'foo_t'}} +template <> void foo_t<int>() {} // expected-warning {{function 'foo_t' is not needed and will not be emitted}} - template <int> - void bar() { - foo(); - } +template <int> +void bar() { + foo(); + foo_t<int>(); + foo_t<void>(); +} } namespace test5 { @@ -142,8 +151,15 @@ 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; // expected-warning{{not needed and will not be emitted}} + static const double d = 0.0; // expected-warning{{variable 'd' is not needed and will not be emitted}} int y = sizeof(d); + + namespace { + // FIXME: Should be "unused variable template 'var_t'" instead. + template <typename T> const double var_t = 0; // expected-warning {{unused variable 'var_t'}} + template <> const double var_t<int> = 0; // expected-warning {{variable 'var_t' is not needed and will not be emitted}} + int z = sizeof(var_t<int>); // expected-warning {{unused variable 'z'}} + } // namespace } namespace unused_nested { @@ -158,9 +174,9 @@ namespace unused_nested { namespace unused { struct { - void func() { // expected-warning {{unused member function}} + void func() { // expected-warning {{unused member function 'func'}} } - } x; // expected-warning {{unused variable}} + } x; // expected-warning {{unused variable 'x'}} } namespace test6 { @@ -201,8 +217,8 @@ static void func() {} } namespace test9 { -template<typename T> -static void completeRedeclChainForTemplateSpecialization() { } // expected-warning {{unused}} +template <typename T> +static void completeRedeclChainForTemplateSpecialization() {} // expected-warning {{unused function template 'completeRedeclChainForTemplateSpecialization'}} } namespace test10 { @@ -216,8 +232,8 @@ constexpr T pi = T(3.14); namespace pr19713 { #if __cplusplus >= 201103L // FIXME: We should warn on both of these. - static constexpr int constexpr3() { return 1; } // expected-warning {{unused}} - constexpr int constexpr4() { return 2; } +static constexpr int constexpr3() { return 1; } // expected-warning {{unused function 'constexpr3'}} +constexpr int constexpr4() { return 2; } #endif } diff --git a/clang/test/SemaCXX/warn-variable-not-needed.cpp b/clang/test/SemaCXX/warn-variable-not-needed.cpp index 0fb0f8151b44..139c2923f4ba 100644 --- a/clang/test/SemaCXX/warn-variable-not-needed.cpp +++ b/clang/test/SemaCXX/warn-variable-not-needed.cpp @@ -2,9 +2,14 @@ namespace test1 { static int abc = 42; // expected-warning {{variable 'abc' is not needed and will not be emitted}} + + namespace { + template <typename T> int abc_template = 0; + template <> int abc_template<int> = 0; // expected-warning {{variable 'abc_template' is not needed and will not be emitted}} + } // namespace template <typename T> int foo(void) { - return abc; + return abc + abc_template<int> + abc_template<long>; } } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits