Skip to content

Reorganize -Winitializer-overrides and -Wreorder-init-list #136586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2025

Conversation

AaronBallman
Copy link
Collaborator

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

These are both now grouped under -Wc99-designator as they both relate
to the C99 feature as it was introduced into C++20.

Fixes llvm#47037
@AaronBallman AaronBallman added clang Clang issues not falling into any other category c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Apr 21, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 21, 2025

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/136586.diff

4 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (+3)
  • (modified) clang/include/clang/Basic/DiagnosticGroups.td (+10-7)
  • (added) clang/test/SemaCXX/cxx20-c99-designator.cpp (+21)
  • (modified) clang/test/SemaCXX/decltype.cpp (-9)
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@+3 {{initializer partially overrides}}
-  // expected-note@+2 {{previous initialization}}
-  // expected-note@+1 {{previous definition}}
   template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
 
-  // expected-warning@+3 {{initializer partially overrides}}
-  // expected-note@+2 {{previous initialization}}
   template<class T>
   void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'r' }))) {} // okay
 
-  // expected-warning@+3 {{initializer partially overrides}}
-  // expected-note@+2 {{previous initialization}}
   template<class T>
   void foo(decltype(T(LP1{ .p1 = { "foo" }, .p1.x[1] = 'x'}))) {} // okay
 
-  // expected-warning@+3 {{initializer partially overrides}}
-  // expected-note@+2 {{previous initialization}}
   // expected-error@+1 {{redefinition of 'foo'}}
   template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
 }

@AaronBallman AaronBallman merged commit 3d91a71 into llvm:main Apr 22, 2025
12 checks passed
@AaronBallman AaronBallman deleted the aballman-gh47037 branch April 22, 2025 11:58
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
These are both now grouped under -Wc99-designator as they both relate to
the C99 feature as it was introduced into C++20.

Fixes llvm#47037
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
These are both now grouped under -Wc99-designator as they both relate to
the C99 feature as it was introduced into C++20.

Fixes llvm#47037
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
These are both now grouped under -Wc99-designator as they both relate to
the C99 feature as it was introduced into C++20.

Fixes llvm#47037
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

C++20 Designated Initializers - Multiple initializations of same struct member
3 participants