[clang] b8c08f7 - [clang][Sema] Fix diagnostic message for unused constant variable templates
Takuya Shimizu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 14 05:44:57 PDT 2023
Author: Takuya Shimizu
Date: 2023-06-14T21:43:03+09:00
New Revision: b8c08f7ae86da4723f9e125d5defa5404518d87d
URL: https://github.com/llvm/llvm-project/commit/b8c08f7ae86da4723f9e125d5defa5404518d87d
DIFF: https://github.com/llvm/llvm-project/commit/b8c08f7ae86da4723f9e125d5defa5404518d87d.diff
LOG: [clang][Sema] Fix diagnostic message for unused constant variable templates
BEFORE this patch, unused const-qualified variable templates such as `template <typename T> const double var_t = 0;` were diagnosed as `unused variable 'var_t'`
This patch fixes this message to `unused variable template 'var_t'`
Differential Revision: https://reviews.llvm.org/D152796
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/Sema.cpp
clang/test/SemaCXX/warn-unused-filescoped.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2960183eb8c5f..32cc7c94a3252 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -342,6 +342,8 @@ Improvements to Clang's diagnostics
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
-------------------------
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index e6507d8808011..09084176cbf41 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1380,6 +1380,9 @@ void Sema::ActOnEndOfTranslationUnit() {
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 @@ void Sema::ActOnEndOfTranslationUnit() {
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
index d53608003b16d..be8d350855c07 100644
--- a/clang/test/SemaCXX/warn-unused-filescoped.cpp
+++ b/clang/test/SemaCXX/warn-unused-filescoped.cpp
@@ -155,8 +155,7 @@ namespace test5 {
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
More information about the cfe-commits
mailing list