Rule:"constexpr must be evaluate at compile time".
Let's look below code (generic example);
const double k1 = size_of_array();
k1 is constant, the value of its initializer is not known compile time but its initializer is known until run time so k1 is not constant expression. As a result a const variable is not constexpr.
But compiler see these code:
const int k1 = 10;
constexpr int k2 = 2*k1;
One exception occurs. A constexpr integral value can be used wherever a const integer is required, such as in template arguments and array declarations [1].
You can get extra information from the links below:
- Constexpr - Generalized Constant Expressions in C++11
- const vs constexpr on variables | stackoverflow
- Difference between constexpr and const | stackoverflow