See the following example:
#include <climits> #include <cstddef> #include <type_traits> template <int n> class MyClass { public: //See: http://stackoverflow.com/a/21298525/688624 template <typename T, typename=typename std::enable_if<std::is_integral<T>::value>::type/*,typename=typename std::enable_if<std::is_unsigned<T>::value>::type*/> static constexpr T get_next_pot(T value, size_t maxb=sizeof(T)*CHAR_BIT,size_t curb=1) { return maxb<=curb ? value : get_next_pot( ((value-1) | ((value-1)>>curb))+1, maxb, curb<<1 ); } public: enum { NEXT_POT = get_next_pot(n) }; }; int main(void) { MyClass<6> mat; return 0; }
This produces:
1>..\main.cpp(15): error : function call must have a constant value in a constant expression
1> NEXT_POT = get_next_pot(n)
1> ^
1> detected during instantiation of class "MyClass<n> [with n=6]" at line 20
MSVC, Clang, and GCC all compile it fine. Moving the function "get_next_pot(...)" outside of the class causes it to compile correctly.