Are variable length arrays an extension in Clang too?

Yes, variable length arrays are supported in clang 3.2/3.3 contrary to the C++11 Standard (§ 8.3.4/1).

So as you say, a program such as:

#include <random>

int random_int_function(int i) 
{
    std::default_random_engine generator;
    std::uniform_int_distribution<int> distribution(1,100);

    int random_int = distribution(generator);  

    return i + random_int;
}

int main() {
    int myArray[ random_int_function( 0 ) ];
    (void)myArray;
    return 0;
}

compiles and runs. However, with the options -pedantic; -std=c++11 that you say you passed, clang 3.2/3,3 diagnoses:

warning: variable length arrays are a C99 feature [-Wvla]

The behaviour matches that of gcc (4.7.2/4.8.1), which warns more emphatically:

warning: ISO C++ forbids variable length array ‘myArray’ [-Wvla]

To make the diagnostic be an error, for either compiler, pass -Werror=vla.

Tags:

C++11