A constant must be initialized from a constant expression (an expression parsed at compile time).
In C ++ 03, the set of constant operations with which you could build constant expressions was extremely dense. Only bare integrals and mathematical operations on them.
To use a user-defined function in constant expression, you need to:
- C ++ 11 or more
- the specified function should be marked
constexpr
This is why adding the -std=c++11 flag to Clang helped: it allowed constexpr "switch" to an improved implementation of the standard library that uses constexpr for std::numeric_limits<T>::max() .
Note. If you are using a newer version of Clang, C ++ 11 will be the default, and the constexpr flag constexpr not be needed.
source share