[PATCH] D152796: [clang][Sema] Fix diagnostic message for unused constant varialbe templates
Takuya Shimizu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 13 03:17:25 PDT 2023
hazohelet created this revision.
hazohelet added reviewers: aaron.ballman, tbaeder, shafik.
Herald added a project: All.
hazohelet requested review of this revision.
Herald added a project: clang.
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'`
Repository:
rG LLVM Github Monorepo
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
@@ -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
-------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152796.530844.patch
Type: text/x-patch
Size: 2597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230613/25e71122/attachment-0001.bin>
More information about the cfe-commits
mailing list