4 ms·
If you're using clang you can just turn on -Wpessimizing-move and the compiler will tell you when you have a std::move call that is inhibiting RVO. The rule of
by hendzen 10y ago
If you're using clang you can just turn on -Wpessimizing-move and the compiler will tell you when you have a std::move call that is inhibiting RVO.
The rule of thumb is don't use std::move on a return value unless you are returning a move-only type (which forces you to do so).
- frankzinger 10y ago> The rule of thumb is don't use std::move on a return value unless you are returning a move-only type (which forces you to do so). RVO will be automatically applied if the returned variable is local to a function and of the same type as the function's return type. That's all that the standard allows. RVO is not applied to function arguments, regardless of whether or not they're rvalue references. So your rule of thumb breaks for cases such as these (X is a movable and copyable type): X f(X&& x) { return x; // x is copied, not moved } In order to get x moved into the return location, you would need to do move it explicitly. Source: Effective Modern C++ by Meyers.
- cpeterso 10y agobtw, -Wpessimizing-move is included in clang's -Wall warnings. clang's warning documentation is poor, but the source code shows that -Wpessimizing-move and -Wredundant-move are included in -Wmove, which is included in -Wmost, which is included in -Wall: https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/DiagnosticGroups.td https://github.com/llvm-mirror/clang/blob/master/include/cla...