Document: P3899R1
Authors: Jan Schultke, Matthias Kretz
Date: 2026-02-20
Audience: SG6, EWG, CWG
CWG cannot agree on whether floating-point overflow is undefined behavior. Is FLT_MAX * 2 UB? Is infinity() + 1 UB? Is merely yielding infinity UB? Extensive CWG discussion found no consensus on what the current wording says. This paper proposes to clarify: overflow on IEEE 754 types produces infinity (defined behavior), and allows infinity arithmetic including in constant expressions. Non-IEEE types get implementation-defined behavior.
The fact that CWG couldn't agree on whether
FLT_MAX * 2is UB in 2026 is genuinely disturbing. Every compiler produces infinity. IEEE 754 defines the result. The standard should have said this twenty years ago.The "every compiler" part is only true for IEEE 754 targets. Some embedded DSPs and historical mainframes don't use IEEE floats. The paper handles this correctly - defined behavior for IEEE, implementation-defined for everything else. Both sides win.
Allowing infinity in constant expressions is the right call. If
constexpr float x = 1e38f * 1e38f;is ill-formed but the runtime version produces infinity, that's an inconsistency between compile-time and runtime semantics. The paper eliminates the inconsistency.If overflow is UB, optimizers can assume it never happens. That enables
-ffinite-math-onlystyle optimizations by default. Making overflow defined behavior means compilers lose that optimization freedom on IEEE targets. The performance cost is likely negligible in practice but it's worth noting the tradeoff.No compiler currently assumes overflow is UB for optimization purposes.
-ffinite-math-onlyis an explicit opt-in flag precisely because assuming no infinities breaks real code. The paper is standardizing existing practice, not changing it.R1 adds underflow investigation and decides to allow it in constant expressions too. Consistent: if the runtime produces denormals on underflow, the compile-time should too. Good to see both edge cases handled together.
Schultke and Kretz again. The
std::arraypaper, the simd papers, now floating-point clarification. They're systematically cleaning up spec corners. The committee should buy them coffee.