According to the C++ standard the size of an array must be greater than zero and a compile time constant and If the array is a VLA then it must have automatic storage duration, i.e. the array must be made local. In other words:
#include<iostream>
int size = 10;
constexpr int Size = 10;
int ar[size]; /* error as size is not a compile time constant and ar does not have auto storage class. */
int Ar[Size]; // fine, no error as Size is a compile time constant.
int main()
{
int arr[size]; // fine as arr has auto storage class.
return 0;
}
So, my question is - why can’t we have a VLA in C++ with static storage duration?