Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.31 KB

c26478.md

File metadata and controls

54 lines (42 loc) · 1.31 KB
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
C26478
C26478
C++

Warning C26478: 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.

When called on a const object, std::move returns a copy of the object, which is likely not the developer's intent.

Example 1

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.

Example 2

struct s;

template <typename T>
void bar(T t){};

void foo()
{
    const s s1;
    bar(std::move(s1)); // C26478 reported here
}

See also

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