diff --git a/clang/docs/DiagnosticsReference.rst b/clang/docs/DiagnosticsReference.rst --- a/clang/docs/DiagnosticsReference.rst +++ b/clang/docs/DiagnosticsReference.rst @@ -4481,6 +4481,35 @@ +-----------------------------------------------------------------------------------------------------------------------------+ +-Wexcess-initializers +--------------------- +This diagnostic is enabled by default. + +**Diagnostic text:** + ++-----------------------------------------------------------------+--------------------+-------------------------------+ +|:warning:`warning:` |nbsp| :diagtext:`excess elements in` |nbsp| |+------------------+| |nbsp| :diagtext:`initializer`| +| ||:diagtext:`array` || | +| |+------------------+| | +| ||:diagtext:`vector`|| | +| |+------------------+| | +| ||:diagtext:`scalar`|| | +| |+------------------+| | +| ||:diagtext:`union` || | +| |+------------------+| | +| ||:diagtext:`struct`|| | +| |+------------------+| | ++-----------------------------------------------------------------+--------------------+-------------------------------+ + ++--------------------------------------------------------------------------------+ +|:warning:`warning:` |nbsp| :diagtext:`excess elements in char array initializer`| ++--------------------------------------------------------------------------------+ + ++------------------------------------------------------------------------------------+ +|:warning:`warning:` |nbsp| :diagtext:`initializer-string for char array is too long`| ++------------------------------------------------------------------------------------+ + + -Wexit-time-destructors ----------------------- **Diagnostic text:** diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -350,6 +350,7 @@ DanglingGsl, ReturnStackAddress]>; def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; +def ExcessInitializers : DiagGroup<"excess-initializers">; def ExpansionToDefined : DiagGroup<"expansion-to-defined">; def FlagEnum : DiagGroup<"flag-enum">; def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -5396,15 +5396,18 @@ def err_excess_initializers : Error< "excess elements in %select{array|vector|scalar|union|struct}0 initializer">; def ext_excess_initializers : ExtWarn< - "excess elements in %select{array|vector|scalar|union|struct}0 initializer">; + "excess elements in %select{array|vector|scalar|union|struct}0 initializer">, + InGroup; def err_excess_initializers_in_char_array_initializer : Error< "excess elements in char array initializer">; def ext_excess_initializers_in_char_array_initializer : ExtWarn< - "excess elements in char array initializer">; + "excess elements in char array initializer">, + InGroup; def err_initializer_string_for_char_array_too_long : Error< "initializer-string for char array is too long">; def ext_initializer_string_for_char_array_too_long : ExtWarn< - "initializer-string for char array is too long">; + "initializer-string for char array is too long">, + InGroup; def warn_missing_field_initializers : Warning< "missing field %0 initializer">, InGroup, DefaultIgnore; diff --git a/clang/test/Misc/warning-flags.c b/clang/test/Misc/warning-flags.c --- a/clang/test/Misc/warning-flags.c +++ b/clang/test/Misc/warning-flags.c @@ -18,12 +18,9 @@ The list of warnings below should NEVER grow. It should gradually shrink to 0. -CHECK: Warnings without flags (75): -CHECK-NEXT: ext_excess_initializers -CHECK-NEXT: ext_excess_initializers_in_char_array_initializer +CHECK: Warnings without flags (72): CHECK-NEXT: ext_expected_semi_decl_list CHECK-NEXT: ext_explicit_specialization_storage_class -CHECK-NEXT: ext_initializer_string_for_char_array_too_long CHECK-NEXT: ext_missing_declspec CHECK-NEXT: ext_missing_whitespace_after_macro_name CHECK-NEXT: ext_new_paren_array_nonconst diff --git a/clang/test/Sema/array-init.c b/clang/test/Sema/array-init.c --- a/clang/test/Sema/array-init.c +++ b/clang/test/Sema/array-init.c @@ -148,11 +148,20 @@ static char const yy[5] = "test"; static char const zz[3] = "test"; // expected-warning{{initializer-string for char array is too long}} +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wexcess-initializers" +static char const zz_quiet[3] = "test"; +#pragma clang diagnostic pop + void charArrays() { static char const test[] = "test"; int test_sizecheck[(sizeof(test) / sizeof(char)) == 5? 1 : -1]; static char const test2[] = { "weird stuff" }; static char const test3[] = { "test", "excess stuff" }; // expected-warning{{excess elements in char array initializer}} +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wexcess-initializers" + static char const test3_quiet[] = {"test", "excess stuff"}; +#pragma clang diagnostic pop char* cp[] = { "Hello" }; diff --git a/clang/test/Sema/init.c b/clang/test/Sema/init.c --- a/clang/test/Sema/init.c +++ b/clang/test/Sema/init.c @@ -121,6 +121,10 @@ }; struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}} +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wexcess-initializers" +struct foo2 bar3_silent = {1, 2}; +#pragma clang diagnostic pop int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0);