description | title | ms.date | f1_keywords | helpviewer_keywords | |||
---|---|---|---|---|---|---|---|
Learn more about: Warning C26478: Don't use std::move on constant variables. (es.56) |
Warning C26478 |
10/12/2023 |
|
|
Don't use
std::move
on 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.
Because const
objects can't be moved, calling std::move
on them has no effect. This pattern can result in unintended copies.
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
// ...
}
To fix the issue, remove the redundant std::move
.
ES.56 - Write std::move()
only when you need to explicitly move an object to another scope