3 ms·
Indeed, this is strictly worse than rust. The object is alive but in an invalid state, so using it is a bug but not one the compiler catches. In the worse case
by ben-schaaf 1y ago
Indeed, this is strictly worse than rust. The object is alive but in an invalid state, so using it is a bug but not one the compiler catches. In the worse case the move is only destructive for larger objects (like SSO), so your tests can pass and you've still got a bug.
- Aeolos 1y agoOr when you enable optimizations and since accessing an object with invalid state is UB, the compiler helpfully decides it is now permitted to format your hard drive. https://gcc.gnu.org/legacy-ml/gcc/2016-02/msg00381.html https://gcc.gnu.org/legacy-ml/gcc/2016-02/msg00381.html "The fact is, undefined compiler behavior is never a good idea. Not for serious projects."
- oconnor663 1y agoC++ teachers like Herb Sutter like to jump in here and make a correction: A moved-from object is in a valid state, you just might not know which state. You can still call methods on it that are valid in any state. ("What is your length?") But you shouldn't fall methods that are only valid in some states. ("Give me your first element.")