[clang] Reorganize -Winitializer-overrides and -Wreorder-init-list (PR #136586)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 21 10:42:47 PDT 2025
https://github.com/AaronBallman created https://github.com/llvm/llvm-project/pull/136586
These are both now grouped under -Wc99-designator as they both relate to the C99 feature as it was introduced into C++20.
Fixes #47037
>From 49dcc67a3a448a3339c40ffb8b0fe58489e7554a Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron at aaronballman.com>
Date: Mon, 21 Apr 2025 13:40:19 -0400
Subject: [PATCH] Reorganize -Winitializer-overrides and -Wreorder-init-list
These are both now grouped under -Wc99-designator as they both relate
to the C99 feature as it was introduced into C++20.
Fixes #47037
---
clang/docs/ReleaseNotes.rst | 3 +++
clang/include/clang/Basic/DiagnosticGroups.td | 17 ++++++++-------
clang/test/SemaCXX/cxx20-c99-designator.cpp | 21 +++++++++++++++++++
clang/test/SemaCXX/decltype.cpp | 9 --------
4 files changed, 34 insertions(+), 16 deletions(-)
create mode 100644 clang/test/SemaCXX/cxx20-c99-designator.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7417fdd71a392..510f16b1ad88c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -402,6 +402,9 @@ Improvements to Clang's diagnostics
they're only triggered if the authors are already making the choice to use
``preferred_type`` attribute.
+- ``-Winitializer-overrides`` and ``-Wreorder-init-list`` are now grouped under
+ the ``-Wc99-designator`` diagnostic group, as they also are about the
+ behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037
Improvements to Clang's time-trace
----------------------------------
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index b29fe40b05c6f..59036b695da85 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -184,6 +184,13 @@ def AbstractFinalClass : DiagGroup<"abstract-final-class">;
def FinalDtorNonFinalClass : DiagGroup<"final-dtor-non-final-class">;
def GNUOffsetofExtensions : DiagGroup<"gnu-offsetof-extensions">;
+def InitializerOverrides : DiagGroup<"initializer-overrides">;
+// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
+def : DiagGroup<"override-init", [InitializerOverrides]>;
+def ReorderCtor : DiagGroup<"reorder-ctor">;
+def ReorderInitList : DiagGroup<"reorder-init-list">;
+def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
+
def CXX11CompatDeprecatedWritableStr :
DiagGroup<"c++11-compat-deprecated-writable-strings">;
@@ -250,7 +257,9 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
def CXX20Designator : DiagGroup<"c++20-designator">;
// Allow -Wno-c99-designator to be used to turn off all warnings on valid C99
// designators (including the warning controlled by -Wc++20-designator).
-def C99Designator : DiagGroup<"c99-designator", [CXX20Designator]>;
+def C99Designator : DiagGroup<"c99-designator", [CXX20Designator,
+ InitializerOverrides,
+ ReorderInitList]>;
def GNUDesignator : DiagGroup<"gnu-designator">;
def DtorName : DiagGroup<"dtor-name">;
@@ -595,9 +604,6 @@ def NullabilityCompleteness : DiagGroup<"nullability-completeness",
def NullArithmetic : DiagGroup<"null-arithmetic">;
def NullCharacter : DiagGroup<"null-character">;
def NullDereference : DiagGroup<"null-dereference">;
-def InitializerOverrides : DiagGroup<"initializer-overrides">;
-// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
-def : DiagGroup<"override-init", [InitializerOverrides]>;
def NonNull : DiagGroup<"nonnull">;
def NonPODVarargs : DiagGroup<"non-pod-varargs">;
def ClassVarargs : DiagGroup<"class-varargs", [NonPODVarargs]>;
@@ -919,9 +925,6 @@ def UsedButMarkedUnused : DiagGroup<"used-but-marked-unused">;
def UsedSearchPath : DiagGroup<"search-path-usage">;
def UserDefinedLiterals : DiagGroup<"user-defined-literals">;
def UserDefinedWarnings : DiagGroup<"user-defined-warnings">;
-def ReorderCtor : DiagGroup<"reorder-ctor">;
-def ReorderInitList : DiagGroup<"reorder-init-list">;
-def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
def UndeclaredSelector : DiagGroup<"undeclared-selector">;
def ImplicitAtomic : DiagGroup<"implicit-atomic-properties">;
def AtomicAlignment : DiagGroup<"atomic-alignment">;
diff --git a/clang/test/SemaCXX/cxx20-c99-designator.cpp b/clang/test/SemaCXX/cxx20-c99-designator.cpp
new file mode 100644
index 0000000000000..b8c141a30a261
--- /dev/null
+++ b/clang/test/SemaCXX/cxx20-c99-designator.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override,reorder -Werror=c99-designator %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override -Wno-reorder-init-list -Werror=initializer-overrides %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=reorder -Wno-initializer-overrides -Werror=reorder-init-list %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=good -Wno-c99-designator %s
+// good-no-diagnostics
+
+// Ensure that -Wc99-designator controls both -Winitializer-overrides and
+// -Wreorder-init-list.
+
+struct X {
+ int a;
+ int b;
+};
+
+void test() {
+ X x{.a = 0, // override-note {{previous initialization is here}}
+ .a = 1}; // override-error {{initializer overrides prior initialization of this subobject}}
+ X y{.b = 0, // reorder-note {{previous initialization for field 'b' is here}}
+ .a = 1}; // reorder-error {{ISO C++ requires field designators to be specified in declaration order; field 'b' will be initialized after field 'a'}}
+}
+
diff --git a/clang/test/SemaCXX/decltype.cpp b/clang/test/SemaCXX/decltype.cpp
index 76d6a041d6dcc..7b67c6db18e95 100644
--- a/clang/test/SemaCXX/decltype.cpp
+++ b/clang/test/SemaCXX/decltype.cpp
@@ -80,23 +80,14 @@ namespace D5789 {
struct P1 { char x[6]; } g1 = { "foo" };
struct LP1 { struct P1 p1; };
- // expected-warning at +3 {{initializer partially overrides}}
- // expected-note at +2 {{previous initialization}}
- // expected-note at +1 {{previous definition}}
template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
- // expected-warning at +3 {{initializer partially overrides}}
- // expected-note at +2 {{previous initialization}}
template<class T>
void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'r' }))) {} // okay
- // expected-warning at +3 {{initializer partially overrides}}
- // expected-note at +2 {{previous initialization}}
template<class T>
void foo(decltype(T(LP1{ .p1 = { "foo" }, .p1.x[1] = 'x'}))) {} // okay
- // expected-warning at +3 {{initializer partially overrides}}
- // expected-note at +2 {{previous initialization}}
// expected-error at +1 {{redefinition of 'foo'}}
template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
}
More information about the cfe-commits
mailing list