aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
diff options
context:
space:
mode:
authorMartin Bohme <mboehme@google.com>2016-08-30 12:11:12 +0000
committerMartin Bohme <mboehme@google.com>2016-08-30 12:11:12 +0000
commitb1ce6c6d5713b8c39eadcddcd9839a8c61b0bd7b (patch)
tree1f3c654ceedbc4d72d56f8cda339de73d65a76b7 /clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
parente5721d659c108e9ae96b1ab8146d3e882572cf67 (diff)
downloadllvm-b1ce6c6d5713b8c39eadcddcd9839a8c61b0bd7b.zip
llvm-b1ce6c6d5713b8c39eadcddcd9839a8c61b0bd7b.tar.gz
llvm-b1ce6c6d5713b8c39eadcddcd9839a8c61b0bd7b.tar.bz2
[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
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
index abaf4b1..ac6e47e 100644
--- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
@@ -27,6 +27,7 @@
#include "MisplacedWideningCastCheck.h"
#include "MoveConstantArgumentCheck.h"
#include "MoveConstructorInitCheck.h"
+#include "MoveForwardingReferenceCheck.h"
#include "MultipleStatementMacroCheck.h"
#include "NewDeleteOverloadsCheck.h"
#include "NoexceptMoveConstructorCheck.h"
@@ -92,6 +93,8 @@ public:
"misc-move-const-arg");
CheckFactories.registerCheck<MoveConstructorInitCheck>(
"misc-move-constructor-init");
+ CheckFactories.registerCheck<MoveForwardingReferenceCheck>(
+ "misc-move-forwarding-reference");
CheckFactories.registerCheck<MultipleStatementMacroCheck>(
"misc-multiple-statement-macro");
CheckFactories.registerCheck<NewDeleteOverloadsCheck>(