title | description | ms.date | f1_keywords | helpviewer_keywords | |||
---|---|---|---|---|---|---|---|
Warning C26479 |
Learn more about: Warning C26479: Don't use std::move to return a local variable. (f.48) |
10/12/2023 |
|
|
Don't use std::move to return a local variable. (f.48)
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::move
s can prevent copy elision.
Code analysis name: NO_MOVE_RET_ON_LOCALS
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
}
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