[PATCH] D43322: Diagnose cases of "return x" that should be "return std::move(x)" for efficiency
Arthur O'Dwyer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 5 13:35:00 PST 2018
Quuxplusone added a comment.
@rtrieu (and perhaps @rsmith) ping?
The action items I need help with are:
- Review and land the refactoring patch https://reviews.llvm.org/D43898 (I don't have commit privs)
- Ideally, test compiling a bunch of (e.g. Google) code with https://reviews.llvm.org/D43322, see if there are any rough edges
- Decide whether `-Wmove` should imply `-Wreturn-std-move`
- Review and land the new-diagnostic patch https://reviews.llvm.org/D43322
- Ideally, some discussion of whether I should write a paper for San Diego proposing that C++ *should* move rather than copy in these cases, and whether that possibility should change anything about this patch
Speaking of rough edges, I did find that in my employer's codebase the far-and-away-most-common trigger is `return my_shared_ptr_to_derived_class;` in a function that is declared to return `shared_ptr<base_class>`. This does indeed generate an extra atomic increment/decrement compared to the optimal code, but I could imagine someone considering that a "false positive."
Other than that one questionable scenario, everything else I've found with it so far has been a true positive. There are no positives (either true or false) in LLVM's codebase.
More information about the cfe-commits