문제

constexpr int get () { return 5; }
template<int N> struct Test {};

int main ()
{
  int a[get()];  // ok
  Test< get() > obj;  // error:'int get()' cannot appear in a constant-expression
}

I have compiled this code with ideone. And was wondering that why it's giving compilation error. Is constexpr function not allowed as template argument or it's a bug in the compiler ?

Edit: changed const int get() to int get() Moreover, there is one more bug with ideone is that, if you remove constexpr then still declaring an array is allowed!! I think that's a C99 feature.

도움이 되었습니까?

해결책

GCC 4.5 (at least the version used at Ideone) does not entirely support constexpr, including your valid usage; it waters down to a const. GCC 4.6 and up correctly supports it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top