Skip to content

Commit 8bee95f

Browse files
AaronBallmanIanWood1
authored andcommitted
Reorganize -Winitializer-overrides and -Wreorder-init-list (llvm#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 llvm#47037
1 parent 2fb4bea commit 8bee95f

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ Improvements to Clang's diagnostics
408408
they're only triggered if the authors are already making the choice to use
409409
``preferred_type`` attribute.
410410

411+
- ``-Winitializer-overrides`` and ``-Wreorder-init-list`` are now grouped under
412+
the ``-Wc99-designator`` diagnostic group, as they also are about the
413+
behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037
414+
411415
Improvements to Clang's time-trace
412416
----------------------------------
413417

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ def AbstractFinalClass : DiagGroup<"abstract-final-class">;
184184
def FinalDtorNonFinalClass : DiagGroup<"final-dtor-non-final-class">;
185185
def GNUOffsetofExtensions : DiagGroup<"gnu-offsetof-extensions">;
186186

187+
def InitializerOverrides : DiagGroup<"initializer-overrides">;
188+
// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
189+
def : DiagGroup<"override-init", [InitializerOverrides]>;
190+
def ReorderCtor : DiagGroup<"reorder-ctor">;
191+
def ReorderInitList : DiagGroup<"reorder-init-list">;
192+
def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
193+
187194
def CXX11CompatDeprecatedWritableStr :
188195
DiagGroup<"c++11-compat-deprecated-writable-strings">;
189196

@@ -250,7 +257,9 @@ def Deprecated : DiagGroup<"deprecated", [DeprecatedAnonEnumEnumConversion,
250257
def CXX20Designator : DiagGroup<"c++20-designator">;
251258
// Allow -Wno-c99-designator to be used to turn off all warnings on valid C99
252259
// designators (including the warning controlled by -Wc++20-designator).
253-
def C99Designator : DiagGroup<"c99-designator", [CXX20Designator]>;
260+
def C99Designator : DiagGroup<"c99-designator", [CXX20Designator,
261+
InitializerOverrides,
262+
ReorderInitList]>;
254263
def GNUDesignator : DiagGroup<"gnu-designator">;
255264
def DtorName : DiagGroup<"dtor-name">;
256265

@@ -595,9 +604,6 @@ def NullabilityCompleteness : DiagGroup<"nullability-completeness",
595604
def NullArithmetic : DiagGroup<"null-arithmetic">;
596605
def NullCharacter : DiagGroup<"null-character">;
597606
def NullDereference : DiagGroup<"null-dereference">;
598-
def InitializerOverrides : DiagGroup<"initializer-overrides">;
599-
// For compatibility with GCC; -Woverride-init = -Winitializer-overrides
600-
def : DiagGroup<"override-init", [InitializerOverrides]>;
601607
def NonNull : DiagGroup<"nonnull">;
602608
def NonPODVarargs : DiagGroup<"non-pod-varargs">;
603609
def ClassVarargs : DiagGroup<"class-varargs", [NonPODVarargs]>;
@@ -919,9 +925,6 @@ def UsedButMarkedUnused : DiagGroup<"used-but-marked-unused">;
919925
def UsedSearchPath : DiagGroup<"search-path-usage">;
920926
def UserDefinedLiterals : DiagGroup<"user-defined-literals">;
921927
def UserDefinedWarnings : DiagGroup<"user-defined-warnings">;
922-
def ReorderCtor : DiagGroup<"reorder-ctor">;
923-
def ReorderInitList : DiagGroup<"reorder-init-list">;
924-
def Reorder : DiagGroup<"reorder", [ReorderCtor, ReorderInitList]>;
925928
def UndeclaredSelector : DiagGroup<"undeclared-selector">;
926929
def ImplicitAtomic : DiagGroup<"implicit-atomic-properties">;
927930
def AtomicAlignment : DiagGroup<"atomic-alignment">;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override,reorder -Werror=c99-designator %s
2+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=override -Wno-reorder-init-list -Werror=initializer-overrides %s
3+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=reorder -Wno-initializer-overrides -Werror=reorder-init-list %s
4+
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=good -Wno-c99-designator %s
5+
// good-no-diagnostics
6+
7+
// Ensure that -Wc99-designator controls both -Winitializer-overrides and
8+
// -Wreorder-init-list.
9+
10+
struct X {
11+
int a;
12+
int b;
13+
};
14+
15+
void test() {
16+
X x{.a = 0, // override-note {{previous initialization is here}}
17+
.a = 1}; // override-error {{initializer overrides prior initialization of this subobject}}
18+
X y{.b = 0, // reorder-note {{previous initialization for field 'b' is here}}
19+
.a = 1}; // reorder-error {{ISO C++ requires field designators to be specified in declaration order; field 'b' will be initialized after field 'a'}}
20+
}
21+

clang/test/SemaCXX/decltype.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,14 @@ namespace D5789 {
8080
struct P1 { char x[6]; } g1 = { "foo" };
8181
struct LP1 { struct P1 p1; };
8282

83-
// expected-warning@+3 {{initializer partially overrides}}
84-
// expected-note@+2 {{previous initialization}}
85-
// expected-note@+1 {{previous definition}}
86-
template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
83+
template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {} // expected-note {{previous definition is here}}
8784

88-
// expected-warning@+3 {{initializer partially overrides}}
89-
// expected-note@+2 {{previous initialization}}
9085
template<class T>
9186
void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'r' }))) {} // okay
9287

93-
// expected-warning@+3 {{initializer partially overrides}}
94-
// expected-note@+2 {{previous initialization}}
9588
template<class T>
9689
void foo(decltype(T(LP1{ .p1 = { "foo" }, .p1.x[1] = 'x'}))) {} // okay
9790

98-
// expected-warning@+3 {{initializer partially overrides}}
99-
// expected-note@+2 {{previous initialization}}
10091
// expected-error@+1 {{redefinition of 'foo'}}
10192
template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {}
10293
}

0 commit comments

Comments
 (0)