Reorganize -Winitializer-overrides and -Wreorder-init-list (#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
This commit is contained in:
@@ -408,6 +408,10 @@ 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
|
||||
----------------------------------
|
||||
|
||||
|
||||
@@ -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">;
|
||||
|
||||
21
clang/test/SemaCXX/cxx20-c99-designator.cpp
Normal file
21
clang/test/SemaCXX/cxx20-c99-designator.cpp
Normal file
@@ -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'}}
|
||||
}
|
||||
|
||||
@@ -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' }))) {}
|
||||
template<class T> void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {} // expected-note {{previous definition is here}}
|
||||
|
||||
// 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' }))) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user