gcc/clang "error: ISO C++ forbids ..." in CI
A construct that some compilers accept as an extension is forbidden by the C++ standard. Under -pedantic-errors or a strict standard, the compiler refuses it.
What this error means
A variable-length array, an anonymous struct, or a comma at the end of an enum is rejected with "ISO C++ forbids", though a permissive compiler accepted it.
gcc
buf.cpp:5:7: error: ISO C++ forbids variable length array 'data' [-Werror=vla]
5 | int data[n];
| ^~~~Common causes
How to fix it
Rewrite to standard C++
- Replace the non-standard construct (use std::vector instead of a VLA).
- Keep the code portable across conforming compilers.
gcc
#include <vector>
std::vector<int> data(n); // replaces int data[n];How to prevent it
- Compile with -pedantic during development so non-standard extensions are caught before a stricter CI toolchain rejects them.
Related guides
gcc/clang "warning treated as error" (-Werror) in CIFix gcc/clang "warning treated as error" with -Werror in CI - a warning that is tolerated locally fails the b…
gcc "error: 'for' loop initial declarations are only allowed in C99"Fix gcc "error: 'for' loop initial declarations are only allowed in C99 or C11 mode" in CI - declaring the lo…