[cfe-dev] Variable length arrays with initialization
Frank Redeker via cfe-dev
cfe-dev at lists.llvm.org
Wed Mar 7 23:47:55 PST 2018
Hello list,
Given the following piece of code
int foo (int i) {
char array[i+1] = {0};
if (array[i]) {
return 0;
}
return 1;
}
When compiling with g++ [g++ (GCC) 6.4.0] the code compiles OK.
But when compiling with clang++ [clang version 4.0.1
(tags/RELEASE_401/final)] I get the following error.
array.c++:2:17: error: variable-sized object may not be initialize
My question now is, is this an bug in GCC, or is there an option for
CLANG to compile this code without errors? Or may is there an option for
g++ to let the compile fail on this code?
Frank
More information about the cfe-dev
mailing list