3 ms·
To the extent anything’s to “blame” for the seemingly massive escalation of the “UB Wars”, I think it’s C++. C++’s main contribution to the C evolutionary line
by twoodfin 3y ago
To the extent anything’s to “blame” for the seemingly massive escalation of the “UB Wars”, I think it’s C++.
C++’s main contribution to the C evolutionary line is rich, zero-cost abstraction.
The main determinants of the residual cost of your abstractions in a language like C++ are the effectiveness of heuristic or profile-driven inlining and the aggressive application of fairly basic optimizations (constant propagation, common subexpression elimination, dead-code elimination, …) to the resulting inlined code, which for good reason “looks” like no code any self-respecting developer would actually write.
This is where reasoning from UB becomes essential. The developer didn’t write this code, didn’t express a direct intention: The compiler synthesized a new program from inlined and rewritten pieces of the AST. “Warning” about possible UB in this code doesn’t make any sense, nor does being conservative about “should-be-impossible” states.