| description | Learn more about: Warning C26478: Don't use std::move on constant variables. (es.56) | ||
|---|---|---|---|
| title | Warning C26478 | ||
| ms.date | 07/15/2019 | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
Don't use
std::moveon constant variables. (es.56)
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
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.
struct s;
template <typename T>
void bar(T t){};
void foo()
{
const s s1;
bar(std::move(s1)); // C26478 reported here
}ES.56 - Write std::move() only when you need to explicitly move an object to another scope