I'm trying to evaluate this simple expression at compile time using C++11 new constexpr feature:
template <int a, int b>
class Test
{
static constexpr double c = a / b;
};
But here's what Clang keeps telling me:
Constexpr variable 'c' must be initialized by a constant expression
The weird thing is that the following compiles well:
template <int a, int b>
class Test
{
static constexpr double c = a / 2.f;
};
Do you guys have any idea on why a/b is not a constant expression, and how could I evaluate this at compile time?
Using Clang compiler with -std=c++1y and -stdlib=libc++
Update
The following example causes the error with the original code:
Test<10,0> test1 ;
while:
Test<10,1> test1 ;
does not.