]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: Diagnose compound literal for empty array [PR114266]
authorJoseph Myers <josmyers@redhat.com>
Wed, 20 Nov 2024 21:29:48 +0000 (21:29 +0000)
committerJoseph Myers <josmyers@redhat.com>
Wed, 20 Nov 2024 21:29:48 +0000 (21:29 +0000)
commitd5cebf7e4491ea0306a072ca3368d771a5ff9455
tree700328cbb63c4af2203bcb94c305b11ec9ae4887
parentcf544af03a8b51b3dea1667ea2525dc6a6b4ae08
c: Diagnose compound literal for empty array [PR114266]

As reported in bug 114266, GCC fails to pedwarn for a compound
literal, whose type is an array of unknown size, initialized with an
empty initializer.  This case is disallowed by C23 (which doesn't have
zero-size objects); the case of a named object is diagnosed as
expected, but not that for compound literals.  (Before C23, the
pedwarn for empty initializers sufficed.)  Add a check for this
specific case with a pedwarn.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

PR c/114266

gcc/c/
* c-decl.cc (build_compound_literal): Diagnose array of unknown
size with empty initializer for C23.

gcc/testsuite/
* gcc.dg/c23-empty-init-4.c: New test.
gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/c23-empty-init-4.c [new file with mode: 0644]