std::move called on an unmovable typestd::move used on a class type with no move constructor or move
assignment operator
This defect occurs when you use std::move to move an object of a class
type that does not have a move constructor or move assignment operator.
The use of std::move in statements such
as:
Obj objTo {std::move(objFrom)};
objTo = std::move(objFrom);If the class is expensive to copy, the unintended copy operation can cause a loss of performance.
To make an object of type T movable, add a move
constructor:
T (T&&);
T& operator=(T&&);
T. If the class does not have to directly manage a resource, you can
use compiler-generated move operators using the =default syntax, for
instance:T (T&&) = default;
Otherwise, if a move operation is not required, remove the std::move
call and directly copy the object.
Performance improvements might vary based on the compiler, library implementation, and environment that you are using.
| Group: Performance |
| Language: C++ |
| Default: Off |
Command-Line Syntax:
STD_MOVE_UNMOVABLE_TYPE |
| Impact: Medium |
Const rvalue reference parameter may
cause unnecessary data copies | Const std::move input may cause a more
expensive object copy | Find defects
(-checkers)