diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -340,6 +340,8 @@ can be controlled using ``-fcaret-diagnostics-max-lines=``. - Clang no longer emits ``-Wunused-variable`` warnings for variables declared with ``__attribute__((cleanup(...)))`` to match GCC's behavior. +- Clang now diagnoses unused const-qualified variable template as + "unused variable template" rather than "unused variable". Bug Fixes in This Version ------------------------- diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -1380,6 +1380,9 @@ if (DiagD->isReferenced()) { Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl) << /*variable*/ 1 << DiagD; + } else if (DiagD->getDescribedVarTemplate()) { + Diag(DiagD->getLocation(), diag::warn_unused_template) + << /*variable*/ 1 << DiagD; } else if (DiagD->getType().isConstQualified()) { const SourceManager &SM = SourceMgr; if (SM.getMainFileID() != SM.getFileID(DiagD->getLocation()) || @@ -1387,11 +1390,7 @@ Diag(DiagD->getLocation(), diag::warn_unused_const_variable) << DiagD; } else { - if (DiagD->getDescribedVarTemplate()) - Diag(DiagD->getLocation(), diag::warn_unused_template) - << /*variable*/ 1 << DiagD; - else - Diag(DiagD->getLocation(), diag::warn_unused_variable) << DiagD; + Diag(DiagD->getLocation(), diag::warn_unused_variable) << DiagD; } } } diff --git a/clang/test/SemaCXX/warn-unused-filescoped.cpp b/clang/test/SemaCXX/warn-unused-filescoped.cpp --- a/clang/test/SemaCXX/warn-unused-filescoped.cpp +++ b/clang/test/SemaCXX/warn-unused-filescoped.cpp @@ -155,8 +155,7 @@ int y = sizeof(d); namespace { - // FIXME: Should be "unused variable template 'var_t'" instead. - template const double var_t = 0; // expected-warning {{unused variable 'var_t'}} + template const double var_t = 0; // expected-warning {{unused variable template 'var_t'}} template <> const double var_t = 0; // expected-warning {{variable 'var_t' is not needed and will not be emitted}} int z = sizeof(var_t); // expected-warning {{unused variable 'z'}} } // namespace