r/cpp • u/Secret_Regret7798 • Jul 08 '26
C++26: Standard library hardening -- Sandor Dargo
https://isocpp.org//blog/2026/07/cpp26-standard-library-hardening-sandor-dargo
56
Upvotes
r/cpp • u/Secret_Regret7798 • Jul 08 '26
18
u/jwakely libstdc++ tamer, LWG chair Jul 08 '26
For libstdc++ the command-line options to get a hardened implementation is
-D_GLIBCXX_ASSERTIONSand that is also implied by the-fhardenedoption.Since GCC 16,
-D_GLIBCXX_ASSERTIONSis implied by default for unoptimized builds, use-D_GLIBCXX_NO_ASSERTIONSto prevent that.4
u/anotherprogrammer25 Jul 08 '26
Is it correct that standard C++ arrays will not become "hardening"?
1
u/parkotron Jul 08 '26 edited Jul 08 '26
Edit: I was completely wrong. I misread the changes in P3471r4 and missed the line before the one I quoted.
In my defence, I think phrasing the "Returns:" line as "if `pos < size()`. Otherwise," kinda opened the door to my misinterpretation.
Original comment:
I've been working with C++ since 2005, and today I learned that one is allowed to pass an out-of-range index to std::basic_string::operator[].So the API acts like every `string` has a (near) infinite number of null terminators:Wild. Have any of you ever intentionally used this behaviour?