// HACKER NEWS — CYBERSECURITY
C++26: Standard Library Hardening Experiments
“Hardening” seems to be a very popular term in the C++ World in 2026. In this article we’ll explore what this word means and see some core examples. Can a hardened library make C++ fully safe? Let’s find out.
When you learned about std::vector you may remember that you can access an element at the i-th position using at least two expressions:
The main difference between those two is that [] is unchecked (and can generate undefined behaviour if you try to access an element which is not there), while .at() may throw std::out_of_range (so it’s a well defined behaviour).
In C++26, the Standard introduces the notion of a hardened implementation. Whether a standard-library implementation is hardened, and how that mode is enabled, is implementation-defined.
For std::vector::operator[](size_type pos):
In other words, if you switch this “hardened” mode you’ll get some well specified error/violation rather than just an undefined behaviour.
Note: At the time of writing (August 2026), compiler and library vendors are still completing the C++26 feature. The options below are the current vendor hardening mechanisms and do not necessarily represent complete implementations of P3471/P3697/P3878
We have the following papers that make the whole feature, as of C++26:
To specify hardening in the Standard, this proposal introduces the notion of a hardened precondition. A hardened precondition is a precondition that results in a contract violation in a hardened implementation. Adding hardening to the library largely consists of turning some of the existing preconditions into hardened preconditions in the specification.
What conditions are candidates to get the hardened implementation?