I understand that VLAs are part of C99 but not C++0x. My question is then why and how g++
would compile code with VLAs. I wrote a test case below:
VLAs are a gcc (and clang) compiler extension in C++ mode, documented here. These extensions are enabled by default.
You should see a warning if you compile with -pedantic
.
Funnily, you will not with gcc4.9 and -std=c++14
or -std=c++1y
. As they explain here, they removed the -Wvla
warning in C++14 mode because VLAs were once in the draft for the standard. They did not actually make it in the final version of C++14.
clang still warns in C++14 mode, as it should.
Edit: gcc 5.1 warns in C++14 mode too, so that got updated correctly.