Open
Description
auto f1(auto&& v) { // ok, no warning
return v;
}
// clang-tidy warning: Forwarding reference parameter 'v' is never forwarded inside the function body.
// clang-tidy rule: cppcoreguidelines-missing-std-forward
// see: https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/missing-std-forward.html
template<typename T>
auto f2(T&& v) {
return v;
}
As per P0257, v
shall be moved into the return value if it is an rvalue-reference; otherwise just copy it. So return std::forward<T>(v);
is not necessary; return v;
is enough.
BTW, f1
is totally equivalent to f2
, but f1
is ok while f2
is not. If the warning for f2
is not a false positive, then there must be a false negative for f1
, either one or the other.