[C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)
authorAaron Ballman <aaron@aaronballman.com>
Mon, 3 Apr 2023 19:19:15 +0000 (15:19 -0400)
committerAaron Ballman <aaron@aaronballman.com>
Mon, 3 Apr 2023 19:22:52 +0000 (15:22 -0400)
commit5d8aaad4452f60ba8902e921d9bed606713a8f26
treed0e0f345b8badb989314ddcbe2320c3664ecd95c
parenta71bc5f56d1f992bfd1de2f8e2279b6d5338c6db
[C2x] Implement support for empty brace initialization (WG14 N2900 and WG14 N3011)

This implements support for allowing {} to consistently zero initialize
objects. We already supported most of this work as a GNU extension, but
the C2x feature goes beyond what the GNU extension allowed.

The changes in this patch are:

* Removed the -Wgnu-empty-initializer warning group. The extension is
  now a C2x extension warning instead. Note that use of
  `-Wno-gnu-empty-initializer seems` to be quite low in the wild
(https://sourcegraph.com/search?q=context%3Aglobal+-file%3A.*test.*+%22-Wno-gnu-empty-initializer%22&patternType=standard&sm=1&groupBy=repo
  which currently only gives 8 hits total), so this is not expected to
  be an overly disruptive change. But I'm adding the clang vendors
  review group just in case this expectation is wrong.
* Reworded the diagnostic wording to be about a C2x extension, added a
  pre-C2x compat warning.
* Allow {} to zero initialize a VLA

This functionality is exposed as an extension in all older C modes
(same as the GNU extension was), but does *not* allow the extension for
VLA initialization in C++ due to concern about handling non-trivially
constructible types.

Differential Revision: https://reviews.llvm.org/D147349
20 files changed:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/Parse/ParseInit.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/C/C2x/n2900_n3011.c [new file with mode: 0644]
clang/test/C/C2x/n2900_n3011_2.c [new file with mode: 0644]
clang/test/Sema/array-init.c
clang/test/Sema/complex-init-list.c
clang/test/Sema/compound-literal.c
clang/test/Sema/flexible-array-init.c
clang/test/Sema/gnu-flags.c
clang/test/Sema/sizeless-1.c
clang/test/Sema/vla.c
clang/test/SemaObjC/property.m
clang/test/SemaOpenCL/intel-subgroup-avc-ext-types.cl
clang/www/c_status.html