description | title | keywords | author | ms.author | ms.date | ms.topic | f1_keywords | helpviewer_keywords | dev_langs | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: Warning C26478: Don't use std::move on constant variables. (es.56) |
c26478 |
c26478 |
JordanMaples |
jomaples |
07/15/2019 |
reference |
|
|
|
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.
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