r/cpp • • Aug 13 '26

C++26: std::indirect

https://www.sandordargo.com/blog/2026/08/12/cpp26-indirect
163 Upvotes

157 comments sorted by

View all comments

Show parent comment

4

u/LB-- Professional+Hobbyist Aug 14 '26

Adding onto what wyrn said, imagine you move from a std::string and it happens to be a short string (SSO). An implementation is permitted to skip the extra work of cleaning up the moved-from string, since it would still be in a valid state after being copied as part of the move. If you then read the moved-from string later before clearing or reassigning it, you're going to get stale data randomly depending on whether it was a short string or not. That is objectively a bug in your program with potentially big consequences depending on how that data is used, and yet no UB occurred.