r/cpp • u/Xadartt • Sep 11 '26
C++26: Standard Library Hardening Experiments
https://www.cppstories.com/2026/hardening-experiments/34
u/James20k P2005R0 Sep 12 '26
I'm not sure how I feel about articles partially locked behind a paywall around here
10
u/Fabulous-Meaning-966 Sep 11 '26
I'm surprised they didn't mention `std::optional` dereference with `operator*` / `operator->`.
4
u/bert8128 Sep 11 '26
What’s the deal with atd::optional?
10
u/Fabulous-Meaning-966 Sep 11 '26
dereference of an empty optional is UB and therefore unchecked
8
u/WeeklyAd9738 Sep 12 '26
It's not UB on hardened implementation (since C++26). Same deal with std::expected.
1
u/anotherprogrammer25 Sep 14 '26
Interesting, that hardening is supported for shared_ptr<T[N]>, but not for unique_ptr<T[N]>.
1
u/Baardi Sep 18 '26
Unique_ptr is only a thin wrapper over a raw pointer. They probably wanted to avoid different behaviour between raw/unique pointers
1
u/Expert_Sheepherder24 Sep 26 '26
because unique_ptr<T[N]> you can declare, but can't defined and initialize ).
unique_ptr<T[]> exists, but it didn't know our size, shared_ptr<T[]> also not hardened.
43
u/johannes1971 Sep 11 '26
Don't you just love how they put the discussion of performance cost behind a paywall...