This revision was automatically updated to reflect the committed changes. Closed by commit rGb8c08f7ae86d: [clang][Sema] Fix diagnostic message for unused constant variable templates (authored by hazohelet).
Changed prior to commit: https://reviews.llvm.org/D152796?vs=530844&id=531293#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D152796/new/ https://reviews.llvm.org/D152796 Files: clang/docs/ReleaseNotes.rst clang/lib/Sema/Sema.cpp clang/test/SemaCXX/warn-unused-filescoped.cpp Index: clang/test/SemaCXX/warn-unused-filescoped.cpp =================================================================== --- clang/test/SemaCXX/warn-unused-filescoped.cpp +++ 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 <typename T> const double var_t = 0; // expected-warning {{unused variable 'var_t'}} + template <typename T> const double var_t = 0; // expected-warning {{unused variable template 'var_t'}} template <> const double var_t<int> = 0; // expected-warning {{variable 'var_t<int>' is not needed and will not be emitted}} int z = sizeof(var_t<int>); // expected-warning {{unused variable 'z'}} } // namespace Index: clang/lib/Sema/Sema.cpp =================================================================== --- clang/lib/Sema/Sema.cpp +++ 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; } } } Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -342,6 +342,8 @@ with ``__attribute__((cleanup(...)))`` to match GCC's behavior. - Clang now issues expected warnings for situations of comparing with NULL pointers. (`#42992: <https://github.com/llvm/llvm-project/issues/42992>`_) +- Clang now diagnoses unused const-qualified variable template as + "unused variable template" rather than "unused variable". Bug Fixes in This Version -------------------------
Index: clang/test/SemaCXX/warn-unused-filescoped.cpp =================================================================== --- clang/test/SemaCXX/warn-unused-filescoped.cpp +++ 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 <typename T> const double var_t = 0; // expected-warning {{unused variable 'var_t'}} + template <typename T> const double var_t = 0; // expected-warning {{unused variable template 'var_t'}} template <> const double var_t<int> = 0; // expected-warning {{variable 'var_t<int>' is not needed and will not be emitted}} int z = sizeof(var_t<int>); // expected-warning {{unused variable 'z'}} } // namespace Index: clang/lib/Sema/Sema.cpp =================================================================== --- clang/lib/Sema/Sema.cpp +++ 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; } } } Index: clang/docs/ReleaseNotes.rst =================================================================== --- clang/docs/ReleaseNotes.rst +++ clang/docs/ReleaseNotes.rst @@ -342,6 +342,8 @@ with ``__attribute__((cleanup(...)))`` to match GCC's behavior. - Clang now issues expected warnings for situations of comparing with NULL pointers. (`#42992: <https://github.com/llvm/llvm-project/issues/42992>`_) +- Clang now diagnoses unused const-qualified variable template as + "unused variable template" rather than "unused variable". Bug Fixes in This Version -------------------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits