-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
@llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) ChangesThese 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:
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' }))) {}
}
|
erichkeane
approved these changes
Apr 21, 2025
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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