Skip to content
Latchkey

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++

  1. Replace the non-standard construct (use std::vector instead of a VLA).
  2. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →