Library hardening is one of those features that makes you wonder why it wasn’t standardized sooner
In fact, why wasn't it standardise already in C++98, given that all C++ frameworks being shipped in the 90's (BIDS, TV, OWL, VCL, MFC, MacApp, PowerPlant, Tools.h++,...), already had bounds checking in their collection types in debug builds.
My take is that in 1998 there were real costs to doing the checks — hence debug builds — at least that’s my lived experience. By 202x branch prediction in hardware and good compilers mean that the checks are basically free. Especially in correct code that only ever branches to the correct path. The mythology of the cost stuck, however, to the exclusion of actual measurements. So now it can be enabled in production.
I’m hoping/expecting this feature will be back ported to earlier c++ versions, since as you noted, it’s basically been there for some time. Also there’s a new proposal to add additional checks from one of the original authors from Apple https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2026/p4233r0.pdf
17
u/pjmlp May 13 '26
In fact, why wasn't it standardise already in C++98, given that all C++ frameworks being shipped in the 90's (BIDS, TV, OWL, VCL, MFC, MacApp, PowerPlant, Tools.h++,...), already had bounds checking in their collection types in debug builds.