Skip to content

Latest commit

 

History

History
40 lines (29 loc) · 1007 Bytes

File metadata and controls

40 lines (29 loc) · 1007 Bytes
description Learn more about: Warning C26478: Don't use std::move on constant variables. (es.56)
title Warning C26478
ms.date 10/12/2023
f1_keywords
C26478
NO_MOVE_OP_ON_CONST
helpviewer_keywords
C26478

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