[clang-tidy] Add check 'misc-move-forwarding-reference'
authorMartin Bohme <mboehme@google.com>
Tue, 30 Aug 2016 12:11:12 +0000 (12:11 +0000)
committerMartin Bohme <mboehme@google.com>
Tue, 30 Aug 2016 12:11:12 +0000 (12:11 +0000)
commitb1ce6c6d5713b8c39eadcddcd9839a8c61b0bd7b
tree1f3c654ceedbc4d72d56f8cda339de73d65a76b7
parente5721d659c108e9ae96b1ab8146d3e882572cf67
[clang-tidy] Add check 'misc-move-forwarding-reference'

Summary:
The check emits a warning if std::move() is applied to a forwarding reference, i.e. an rvalue reference of a function template argument type.

If a developer is unaware of the special rules for template argument deduction on forwarding references, it will seem reasonable to apply std::move() to the forwarding reference, in the same way that this would be done for a "normal" rvalue reference.

This has a consequence that is usually unwanted and possibly surprising: If the function that takes the forwarding reference as its parameter is called with an lvalue, that lvalue will be moved from (and hence placed into an indeterminate state) even though no std::move() was applied to the lvalue at the callsite.

As a fix, the check will suggest replacing the std::move() with a std::forward().

This patch requires D23004 to be submitted before it.

Reviewers: sbenza, aaron.ballman

Subscribers: klimek, etienneb, alexfh, aaron.ballman, Prazek, Eugene.Zelenko, mgehre, cfe-commits

Projects: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D22220

llvm-svn: 280077
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/clang-tidy/misc/MoveForwardingReferenceCheck.cpp [new file with mode: 0644]
clang-tools-extra/clang-tidy/misc/MoveForwardingReferenceCheck.h [new file with mode: 0644]
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/docs/clang-tidy/checks/misc-move-forwarding-reference.rst [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/misc-move-forwarding-reference.cpp [new file with mode: 0644]