3 ms·
Move semantics are a good idea, but C++ doesn't have the compiler machinery to catch when you move something away and then try to reference it. Move semantics
by Animats 10y ago
Move semantics are a good idea, but C++ doesn't have the compiler machinery to catch when you move something away and then try to reference it. Move semantics really need a borrow checker, like Rust. In C++, you have to be very, very careful not to do things like accidentally move something passed to you as a non-const ref.
- jguegant 10y agoUse clang tidy: http://clang.llvm.org/extra/clang-tidy/checks/misc-use-after-move.html http://clang.llvm.org/extra/clang-tidy/checks/misc-use-after...
- deleted 10y ago[deleted]
- int_19h 10y agoIn C++, you can't "accidentally" move something that's a non-const ref, since a move from one would require explicit use of std::move. The only things which can be moved accidentally are rvalues and rvalue references. But for rvalues, that doesn't hurt anything; and for rvalue references, the only reason why you'd use one is if you intended to play tricks with move semantics, which implies that you know what you're doing. Basically if you write C++ as if move semantics didn't exist (i.e. never use rvalue references or std::move), you won't shoot yourself in the foot by those means. Of course, this also means that compiler assumptions are fairly pessimistic, so many places that could be a move aren't, because the move has to be explicit.
- deleted 10y ago[deleted]