Using the g++ compiler, both of these compile fine:
constexpr double d1 = 2.0 / 1.0;
const double d2 = 2.0 / 0.0;
But this does not:
constexpr double d2 = 2.0 / 0.0;
The compile-time error is:
error: ‘(2.0e+0 / 0.0)’ is not a constant expression
Note that cppreference gives this exact example, confirming that it’s not allowed.
I don’t understand why it’s not allowed. Keeping in mind that std::numeric_limits::is_iec559 is constexpr, the compiler clearly knows at compile time, within a constexpr, whether divide-by-zero is allowed. So, in the case that it is allowed… why isn’t it allowed within the constexpr?