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.
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::stringand 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.