Author: Aaron Ballman Date: 2023-08-10T07:24:05-04:00 New Revision: 151214b40d869455666ca76548a9e3ad639f79de
URL: https://github.com/llvm/llvm-project/commit/151214b40d869455666ca76548a9e3ad639f79de DIFF: https://github.com/llvm/llvm-project/commit/151214b40d869455666ca76548a9e3ad639f79de.diff LOG: Silently accept -Wgnu-empty-initializer https://github.com/llvm/llvm-project/commit/5d8aaad4452f60ba8902e921d9bed606713a8f26 removed the warning group as the functionality is no longer a GNU extension. However, users have asked for the warning group to be supported so that code transitioning from Clang 16 to Clang 17 has an easier migration path when compiling with -Werror. This patch restores the warning group, but as an ignored warning group because the functionality is now always considered to be a C extension rather than a GNU extension. This allows users to do: -Werror -pedantic -Wno-gnu-empty-intializer -Wno-c2x-extensions to silence the diagnostics in both Clang 16 and Clang 17. Fixes https://github.com/llvm/llvm-project/issues/64357 Differential Revision: https://reviews.llvm.org/D157503 Added: clang/test/Sema/empty-init.c Modified: clang/include/clang/Basic/DiagnosticGroups.td Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 850c3a092e6a9c..ab990aaacc0ebd 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -20,6 +20,7 @@ def DeprecatedStaticAnalyzerFlag : DiagGroup<"deprecated-static-analyzer-flag">; // Empty DiagGroups are recognized by clang but ignored. def ODR : DiagGroup<"odr">; def : DiagGroup<"abi">; +def : DiagGroup<"gnu-empty-initializer">; // Now a C extension, not GNU. def AbsoluteValue : DiagGroup<"absolute-value">; def MisspelledAssumption : DiagGroup<"misspelled-assumption">; def UnknownAssumption : DiagGroup<"unknown-assumption">; diff --git a/clang/test/Sema/empty-init.c b/clang/test/Sema/empty-init.c new file mode 100644 index 00000000000000..8cb4a77710c2b7 --- /dev/null +++ b/clang/test/Sema/empty-init.c @@ -0,0 +1,30 @@ +// RUN: %clang_cc1 %s -std=c2x -Wall -pedantic -fsyntax-only -verify=good +// RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -fsyntax-only -verify=c2x +// RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -Wno-gnu-empty-initializer -fsyntax-only -verify=c2x +// RUN: %clang_cc1 %s -std=c2x -Wgnu-empty-initializer -fsyntax-only -verify=good +// RUN: %clang_cc1 %s -std=c17 -Wall -pedantic -fsyntax-only -verify=c2x-ext +// RUN: %clang_cc1 %s -std=c17 -Wgnu-empty-initializer -fsyntax-only -verify=good +// RUN: %clang_cc1 %s -std=c17 -Wc2x-extensions -fsyntax-only -verify=c2x-ext +// RUN: %clang_cc1 %s -std=c17 -Wpre-c2x-compat -fsyntax-only -verify=good + +// good-no-diagnostics + +// Empty brace initialization used to be a GNU extension, but the feature was +// added to C2x. We now treat empty initialization as a C extension rather than +// a GNU extension. Thus, -Wgnu-empty-initializer is always silently ignored. + +struct S { + int a; +}; + +struct S s = {}; /* c2x-warning {{use of an empty initializer is incompatible with C standards before C2x}} + c2x-ext-warning {{use of an empty initializer is a C2x extension}} + */ + +void func(void) { + struct S s2 = {}; /* c2x-warning {{use of an empty initializer is incompatible with C standards before C2x}} + c2x-ext-warning {{use of an empty initializer is a C2x extension}} + */ + (void)s2; +} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits