警告 C26478

不要对常量变量使用 std::move。 (es.56)

备注

此警告指示 std::move 的使用与 std::move 的预期使用方式不一致。

由于 const 个对象无法移动,因此对它们调用 std::move 是无效的。 此模式可能会导致意外复制。

代码分析名称: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
    // ...
}

要解决此问题,请移除冗余的 std::move

另请参阅

ES.56 - 只在需要将一个对象显式移动到另一范围时才写入 std::move()