clang allows direct list initialization of flexible array member with `{}`
The following code is accepted by clang, which contains an invalid non-static list initialization statement of flexible array member a[]:
struct S {
int bb;
int a[];
};
void f ()
{
S s=S{0,{}};
//rejected
//S s=S{0,{0}};
}
This only happens when the initialization list of a is empty, otherwise the compiler correctly rejects it.
GCC rejects the code. While ICC performs similarly with clang(accepts the first statement but rejects the second one).
@llvm/issue-subscribers-clang-frontend
Author: None (Rush10233)
struct S {
int bb;
int a[];
};
void f ()
{
S s=S{0,{}};
//rejected
//S s=S{0,{0}};
}
This only happens when the initialization list of a is empty, otherwise the compiler correctly rejects it.
GCC rejects the code. While ICC performs similarly with clang(accepts the first statement but rejects the second one).
CC @AaronBallman
It seems that empty flexible array initializers are always permitted as an extension. Should it be changed?
https://github.com/llvm/llvm-project/blob/6ffa995517a9b4c15aba0eb511cba309e21808cf/clang/lib/Sema/SemaInit.cpp#L2199-L2204
I think there are (at least) two bugs here: 1) we should reject {} the same as we reject {0} in C++ mode. 2) Clang accepts VLA initialization as an extension in places GCC does not but we claim it as a GNU extension: https://godbolt.org/z/vYPfqjP7j