5 ms·
"Another difference in Rust is that values cannot be used after a move, while they simply "should not be used, mostly" in C++" That's one of my biggest issues
by DLoupe 10mo ago
"Another difference in Rust is that values cannot be used after a move, while they simply "should not be used, mostly" in C++"
That's one of my biggest issues with C++ today. Objects that can be moved must support a "my value was moved out" state. So every access to the object usually starts with "if (have-a-value())". It also means that the destructor is called for an object that won't be used anymore.
- krona 10mo agoclang-tidy has a check for this. https://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-after-move.html https://clang.llvm.org/extra/clang-tidy/checks/bugprone/use-... MSVC and the Clang static analyzer have a analysis checks for this too. Not sure about GCC. It's worth remembering though that values can be reinitialized in C++, after move.
- DLoupe 10mo agoI think you missed my point. The problem is not lack of guarding against programmer mistakes. It's that the compiler generates unnecessary code.