Muokkaa

Jaa


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.

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

Example

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.

See also

ES.56 - Write std::move() only when you need to explicitly move an object to another scope