Consider the following code:
template<typename T>
constexpr inline T fma(T a, T b, T c)
{
return a * b + c;
}
This compiles just fine. But why does it? In theory, constexpr functions can only call other constexpr functions. However, there is no guarantee that the operators will be constexpr functions. For example, let's say I have some type with the following interface:
class someType
{
someType operator + (const someType &rhs);
someType operator * (const someType &rhs);
};
The operators + and * are not constexpr. If I write the following code:
fma(someType(), someType(), someType());
It should fail to compile because a constexpr function is calling non-constexpr functions. But it compiles just fine. Why is this?
I'm using MinGW's G++ compiler with the -std=c++0x option.