I\'m trying to evaluate this simple expression at compile time using C++11 new constexpr feature:
template
class Test
{
static constexpr
Solved. One of the template instance had b=0
.
Somehow, Clang didn't warn me I was dividing by zero.
And +Inf
is not a constant expression.
The reason why:
Test<10,0> test1 ;
fails is because you have undefined behavior due to division by zero. This is covered in the draft C++ standard section 5.6
[expr.mul] which says:
If the second operand of / or % is zero the behavior is undefined
and constant expressions specifically exclude undefined behavior. I am not sure what version of clang
you are using but the versions I have available online do provide a divide by zero warning (see it live):
note: division by zero
static constexpr double c = a / b;
^