- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for catching this bug, Ian. I could reproduce the issue and will with the developers. Appreciate for letting us know and for your patience through this. I'll keep you updated on the issue progress, thanks.
Kittur

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page