|
|
|
|
|
by virtualritz
561 days ago
|
|
> "Unspecified" means that the implementation gets to decide what is the status of the string after move. For long enough strings, typical implementation strategy is to set the moved-from string in an empty state. Thusly, what happens in code that accesses the string after the move is UB. In the implementation of C++ the article uses the string was just empty.
But for all we know it may still contain a 1:1 copy of the original or 20 copies or a gobbledygook of bytes. Any code that relies on the string being something (even empty) may behave different if it isn't. That's the very definition of UB. "A typical implementation strategy" is meaningless for someone writing code against a language specification. You're then writing code against a specific compiler/std lib and that's fine. But let's be honest about it. |
|
Undefined behavior is a stronger statement and says that if the behavior occurs then the entire program is simply not valid. This allows the compiler to make vastly more aggressive changes to your program.