The following code works well in clang++3.6/g++4.8.2, ubuntu. I am wondering why this code could compile(using -std=c++14/c++11) and also print out the correct result "4". To my understanding the value of *pi could only be calculated at running time and the length of array need to be calculated in compiling time, right?
constexpr int foo(int i,int j)
{
return i+j;
}
int bar(int *p)
{
int i=pow(2,*p);
return i;
}
int main()
{
int *pi = new int;
*pi = 1;
*pi = bar(pi);
int arr3[foo(*pi,*pi)]; // the length of array need to be calculated in compile time
cout<<sizeof(arr3)/sizeof(arr3[0])<<endl;
}