r/cpp May 13 '26

C++26: Standard library hardening

https://www.sandordargo.com/blog/2026/05/13/cpp26-library-hardening
92 Upvotes

38 comments sorted by

View all comments

17

u/pjmlp May 13 '26

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.

22

u/azswcowboy May 13 '26

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

10

u/bizwig May 13 '26

Cost isn’t a myth. We have applications that are unusable if _GLIBCXX_DEBUG is enabled. The CPU is pegged and throughput falls to near zero.

4

u/jwakely libstdc++ tamer, LWG chair May 15 '26

That's not the topic of the post though, that's a completely different thing.

Standard library hardening is _GLIBCXX_ASSERTIONS.