2 ms·
UB is a guaranteed compilation error in constexpr. However, in regular code UB may only become known after multiple optimization passes (e.g. constant propagat
by pornel 2y ago
UB is a guaranteed compilation error in constexpr.
However, in regular code UB may only become known after multiple optimization passes (e.g. constant propagation, inlining).
It's difficult for the optimizer to meaningfully err at that time. The code may have been heavily modified by other optimization passes, which can add UB to the code (e.g. UB may have been data-dependent (1/x), but optimizer added a specialized copy of a function for x=0 where it became unconditional). The IR may have been generated by a non-C language that used UB/poison intentionally to guide optimizations.