Hey Clang Users,
I am having issues compiling the follow piece of code:
#include <stdlib.h>
int main() {
int x = 8;
int y = 8;
double (*testptr)[y][2][2] = (double (*)[y][2][2])
malloc(sizeof(double[y][2][2]));
free(testptr);
return 0;
}
When I run
clang test.cxx -lstdc++ -pedantic
it FAILS with
test.cxx:6:14: error: cannot initialize a variable of type 'double
(*)[y][2][2]' with an rvalue of type 'double (*)[y][2][2]'
double (*testptr)[y][2][2] = (double (*)[y][2][2])
malloc(sizeof(double[y][2][2]));
(and also throws warnings about VLA usage) and as expected, when I
force the language to be C using
clang -x c test.cxx -lstdc++ -pedantic
it succeeds.
However, the corresponding gcc/g++ commands both succeed:
gcc test.cxx -pedantic
g++ test.cxx -pedantic
both succeed (although g++ throws warning about VLA usage, as expected).
I am using clang version 3.6.2-1 on Ubuntu.
Is there any way to make clang behave like g++ in this case? Am I
missing something?
Thanks,
Chris Eldred