VLAs when compiling a C++ source with g++

后端 未结 1 1081
闹比i
闹比i 2020-12-04 03:09

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:

相关标签:
1条回答
  • 2020-12-04 03:55

    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.

    0 讨论(0)
提交回复
热议问题