Is VLA initialization with curly braces a bug or a GCC extension?

Given the following code:

int main()
{
    int n = 3;
    int arr[n] = { 1, 2, 3 };
}

      

GCC native errors in C99 mode error: variable-sized object may not be initialized

, while clang gives the same error in C ++ mode. However, in C ++ mode, GCC doesn't complain. This would lead me to believe that this is a possible extension that is not documented on the C page of the VLA extension . I couldn't find a related bug report either. Can anyone check if this is an extension or if there is an existing bug report?

+3


source to share


1 answer


This new behavior is actually mentioned in , as I suspect it is possible to correlate with the GCC 4.9 release notes :

g ++ supports C ++ 1y variable length arrays. g ++ has supported the GNU / C99-style VLA for a long time, but now additionally supports initializers and capturing lambda by reference. In C ++ 1y mode, g ++ will complain about using VLAs that are not allowed by the draft standard, such as forming a pointer to a VLA type or applying sizeof to a VLA variable. Note that it now appears that VLAs won't be part of C ++ 14, but will be part of a separate document, and then perhaps C ++ 17.



Note that the C ++ standard mode is still gnu++98/gnu++03

for this version.

+3


source







All Articles