flexarray: Accept empty ones

See testcase, it's a GNU extension, but widely accepted (the
linux kernel uses it).  This got broken with 72b520e709.
This commit is contained in:
Michael Matz 2022-07-01 15:37:23 +02:00
parent 9712541156
commit ebb4e71236
2 changed files with 5 additions and 0 deletions

View file

@ -7660,6 +7660,10 @@ static void decl_initializer(init_params *p, CType *type, unsigned long c, int f
}
len = 0;
/* GNU extension: if the initializer is empty for a flex array,
it's size is zero. We won't enter the loop, so set the size
now. */
decl_design_flex(p, s, len);
while (tok != '}' || (flags & DIF_HAVE_ELEM)) {
len = decl_designator(p, type, c, &f, flags, len);
flags &= ~DIF_HAVE_ELEM;

View file

@ -15,6 +15,7 @@ int f1int (void) {
struct wint q = {"bugs"};
return !s[0];
}
int empty[] = {}; // GNU extension
int main (void) {
char s[9]="nonono";
static struct wchar q = {"bugs", {'c'}};