Warning C26478
Don't use
std::move
on constant variables. (es.56)
Remarks
This warning is to indicate that the use of std::move
not consistent with how std::move
is intended to be used.
When called on a const
object, std::move
returns a copy of the object, which is likely not the developer's intent.
Code analysis name: NO_MOVE_OP_ON_CONST
Example 1
struct node
{
node* next;
int id;
};
void foo(const node& n)
{
const node local = std::move(n); // C26478 reported here
// ...
}
An assignment operator or using the passed in parameter will prevent this warning from being issued and will adequately serve the developer's use case.
Example 2
struct s;
template <typename T>
void bar(T t){};
void foo()
{
const s s1;
bar(std::move(s1)); // C26478 reported here
}
See also
ES.56 - Write std::move() only when you need to explicitly move an object to another scope
Feedback
Submit and view feedback for