Some programmers might be tempted to "optimize" the code by putting std::move into the return statement like this:
T fn()
{
T t;
return std::move (t);
}
However, here the call to std::move precludes the NRVO, because it breaks the conditions specified in the C++ standard, namely [class.copy.elision]: the returned expression must be a name. The reason for this is that std::move returns a reference, and in general, the compiler can't know to what object the function returns a reference to. So GCC 9 will issue a warning (when -Wall is in effect):
t.C:8:20: warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
8 | return std::move (t);
| ~~~~~~~~~~^~~
t.C:8:20: note: remove ‘std::move’ call
--
FROM 221.219.211.*