Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 1.11 KB

c26479.md

File metadata and controls

42 lines (32 loc) · 1.11 KB
description title ms.date f1_keywords helpviewer_keywords
Learn more about: Warning C26479: Don't use std::move to return a local variable. (f.48)
Warning C26479
10/12/2023
C26479
NO_MOVE_RET_ON_LOCALS
C26479

Warning C26479

Don't use std::move to return a local variable. (f.48)

Remarks

The return statement is the last use of a local variable, so the compiler uses move semantics to return it whenever possible. Adding a std::move is redundant in this scenario. Moreover, redundant std::moves can prevent copy elision.

Code analysis name: NO_MOVE_RET_ON_LOCALS

Example 1

S foo()
{
    S local1{};
    return std::move(local1); // Warning: C26479
}

To fix this issue, remove the redundant std::move:

S foo()
{
    S local1{};
    return local1; // No warning
}

See also

F.48 - Don't return std::move(local) ES.56 - Write std::move() only when you need to explicitly move an object to another scope