[clang] b0697a1 - Create diagnostic group for definition deprecation warning
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 16 09:36:37 PDT 2023
Author: Nuri Amari
Date: 2023-07-16T12:36:26-04:00
New Revision: b0697a1cb0b539c773548f62402816e2d9b6f107
URL: https://github.com/llvm/llvm-project/commit/b0697a1cb0b539c773548f62402816e2d9b6f107
DIFF: https://github.com/llvm/llvm-project/commit/b0697a1cb0b539c773548f62402816e2d9b6f107.diff
LOG: Create diagnostic group for definition deprecation warning
In https://reviews.llvm.org/D126664, a warning is introduced
warning against the deprecated out of line definition of a
static constexpr member in C++17 and later. Prior to this patch,
the only diagnostic group controlling this diagnostic was -Wdeprecated,
which controls many many diagnostics. This patch creates
a diagnostic group specifically for this warning so it can
be controlled in isolation, while also being included with -Wdeprecated.
Differential Revision: https://reviews.llvm.org/D153881
Added:
clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c501903815955d..8f3bd70f7a2aa1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -386,6 +386,13 @@ Improvements to Clang's diagnostics
on overload resolution, when the actual reason for the failure is loss of other qualifiers.
- Clang's notes about unconvertible types in overload resolution failure now covers
the source range of parameter declaration of the candidate function declaration.
+- Added a new diagnostic warning group
+ ``-Wdeprecated-redundant-constexpr-static-def``, under the existing
+ ``-Wdeprecated`` group. This controls warnings about out-of-line definitions
+ of 'static constexpr' data members that are unnecessary from C++17 onwards.
+
+ Bug Fixes in This Version
+ -------------------------
*Example Code*:
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index cfc1c9bc15bd2d..c0797166585e44 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -186,6 +186,7 @@ def DeprecatedCopyWithDtor : DiagGroup<"deprecated-copy-with-dtor", [DeprecatedC
// For compatibility with GCC.
def : DiagGroup<"deprecated-copy-dtor", [DeprecatedCopyWithDtor]>;
def DeprecatedDeclarations : DiagGroup<"deprecated-declarations">;
+def DeprecatedRedundantConstexprStaticDef : DiagGroup<"deprecated-redundant-constexpr-static-def">;
def UnavailableDeclarations : DiagGroup<"unavailable-declarations">;
def UnguardedAvailabilityNew : DiagGroup<"unguarded-availability-new">;
def UnguardedAvailability : DiagGroup<"unguarded-availability",
@@ -224,7 +225,9 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
DeprecatedThisCapture,
DeprecatedType,
DeprecatedVolatile,
- DeprecatedWritableStr]>,
+ DeprecatedWritableStr,
+ DeprecatedRedundantConstexprStaticDef,
+ ]>,
DiagCategory<"Deprecations">;
def CXX20Designator : DiagGroup<"c++20-designator">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eea4d4961c077a..d9932e0aa31a2a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -447,7 +447,7 @@ def warn_qual_return_type : Warning<
def warn_deprecated_redundant_constexpr_static_def : Warning<
"out-of-line definition of constexpr static data member is redundant "
"in C++17 and is deprecated">,
- InGroup<Deprecated>, DefaultIgnore;
+ InGroup<DeprecatedRedundantConstexprStaticDef>, DefaultIgnore;
def warn_decl_shadow :
Warning<"declaration shadows a %select{"
diff --git a/clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp b/clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
new file mode 100644
index 00000000000000..873fbf1b32cac3
--- /dev/null
+++ b/clang/test/SemaCXX/redundant-out-of-line-static-constexpr-member-def-diag.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++17 -verify %s -Werror -Wdeprecated -Wno-error=deprecated-redundant-constexpr-static-def
+
+namespace {
+ struct A {
+ static constexpr int n = 0;
+ static constexpr int m = 0;
+ };
+ constexpr int A::n; // expected-warning{{out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated}}
+ const int A::m; // expected-warning{{out-of-line definition of constexpr static data member is redundant in C++17 and is deprecated}}
+}
More information about the cfe-commits
mailing list