[clang] 1f6ea2a - Expand definition deprecation warning to include constexpr statements.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 1 08:31:16 PDT 2022
Author: Luke Nihlen
Date: 2022-06-01T11:31:07-04:00
New Revision: 1f6ea2a37c4393a2147cb82c8fe7966a2f690e24
URL: https://github.com/llvm/llvm-project/commit/1f6ea2a37c4393a2147cb82c8fe7966a2f690e24
DIFF: https://github.com/llvm/llvm-project/commit/1f6ea2a37c4393a2147cb82c8fe7966a2f690e24.diff
LOG: Expand definition deprecation warning to include constexpr statements.
Clang currently warns on definitions downgraded to declarations
with a const modifier, but not for a constexpr modifier. This patch
updates the warning logic to warn on both inputs, and adds a test to
check the additional case as well.
See also: https://bugs.chromium.org/p/chromium/issues/detail?id=1284718
Differential Revision: https://reviews.llvm.org/D126664
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/basic/basic.def/p2.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6453f4b302d8b..83db2a7cd38b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -241,6 +241,9 @@ Improvements to Clang's diagnostics
suggest ``#else`` as an alternative. ``#elifdef`` and ``#elifndef`` are only
suggested when in C2x or C++2b mode. Fixes
`Issue 51598 <https://github.com/llvm/llvm-project/issues/51598>`_.
+- The ``-Wdeprecated`` diagnostic will now warn on out-of-line ``constexpr``
+ declarations downgraded to definitions in C++1z, in addition to the
+ existing warning on out-of-line ``const`` declarations.
Non-comprehensive list of changes in this release
-------------------------------------------------
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d68d1f3ff070d..f349a86ec2dac 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4508,15 +4508,15 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
}
// C++ doesn't have tentative definitions, so go right ahead and check here.
- if (getLangOpts().CPlusPlus &&
- New->isThisDeclarationADefinition() == VarDecl::Definition) {
+ if (getLangOpts().CPlusPlus) {
if (Old->isStaticDataMember() && Old->getCanonicalDecl()->isInline() &&
Old->getCanonicalDecl()->isConstexpr()) {
// This definition won't be a definition any more once it's been merged.
Diag(New->getLocation(),
diag::warn_deprecated_redundant_constexpr_static_def);
- } else if (VarDecl *Def = Old->getDefinition()) {
- if (checkVarDeclRedefinition(Def, New))
+ } else if (New->isThisDeclarationADefinition() == VarDecl::Definition) {
+ VarDecl *Def = Old->getDefinition();
+ if (Def && checkVarDeclRedefinition(Def, New))
return;
}
}
diff --git a/clang/test/CXX/basic/basic.def/p2.cpp b/clang/test/CXX/basic/basic.def/p2.cpp
index 598a79a8a3d7d..ccb7a66cff8f0 100644
--- a/clang/test/CXX/basic/basic.def/p2.cpp
+++ b/clang/test/CXX/basic/basic.def/p2.cpp
@@ -5,4 +5,9 @@ namespace {
static constexpr int n = 0;
};
const int A::n; // expected-warning {{deprecated}}
+
+ struct B {
+ static constexpr int m = 0;
+ };
+ constexpr int B::m; // expected-warning {{deprecated}}
}
More information about the cfe-commits
mailing list