[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
Wed Jun 14 05:45:11 PDT 2023
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
-------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152796.531293.patch
Type: text/x-patch
Size: 2609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230614/c3b8616e/attachment.bin>
More information about the cfe-commits
mailing list