`static constexpr` function called in a constant expression is…an error?

As T.C. demonstrated with some links in a comment, the standard is not quite clear on this; a similar problem arises with trailing return types using decltype(memberfunction()). The central problem is that class members are generally not considered to be declared until after the class in which they’re declared is complete. Thus, regardless of the … Read more

Why “initializer element is not a constant” is… not working anymore?

Initializers for objects with static storage duration are required to be composed of constant expressions. As @EugenSh. observed in comments, “constant expression” is a defined term. Specifically, in C2011 it is the subject of section 6.6. The description is simply A constant expression can be evaluated during translation rather than runtime, and accordingly may be … Read more

C++ expected constant expression

float x[size][2]; That doesn’t work because declared arrays can’t have runtime sizes. Try a vector: std::vector< std::array<float, 2> > x(size); Or use new // identity<float[2]>::type *px = new float[size][2]; float (*px)[2] = new float[size][2]; // … use and then delete delete[] px; If you don’t have C++11 available, you can use boost::array instead of std::array. … Read more

Constant expression initializer for static class member of type double

In C++03 we were only allowed to provide an in class initializer for static member variables of const integral of enumeration types, in C++11 we could initialize a static member of literal type in class using constexpr. This restriction was kept in C++11 for const variables mainly for compatibility with C++03. We can see this … Read more

Why are lambda expressions not allowed in an unevaluated operands but allowed in the unevaluated portions of constant expressions?

The core reason for the unevaluated operands exclusion is covered in C++ Standard Core Language Defect Reports and Accepted Issues #1607. Lambdas in template parameters which seeks to clarify this restriction and states the intention of the restriction in section 5.1.2 was to: […] avert the need to deal with them in function template signatures … Read more