isocpp / isocpp/CppCoreGuidelines
[Update Needed, No Longer Always True Since C++23] F.19: For “forward” parameters, pass by TP&& and only std::forward the parameter
Open
@hsutter is already working on this.
Since Aug 6, 2026.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
Consider the following code:
#include <string>
auto f1(auto&& v) {
return v;
}
auto f2(auto&& v) {
return std::forward<decltype(v)>(v);
}
int main() {
return f1(std::string("hello")).size() + f2(std::string("hello")).size();
}
clang will generate the same assembly code for f1 and f2. However,
- As per the C++ core guidelines,
f2is recommended; - As per p0527r1,
f1is enough since C++23. - It's possible that
f2has an extra function call thanf1. We should not depend on the compiler to optimize that out; even if it almost always does.
Should we still always std::forward a universal reference argument? or the C++ core guidelines should be updated?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.