[PATCH] D22220: [clang-tidy] Add check 'misc-move-forwarding-reference'

Martin Böhme via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 11 07:46:43 PDT 2016


mboehme created this revision.
mboehme added a reviewer: sbenza.
mboehme added a subscriber: cfe-commits.

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().

http://reviews.llvm.org/D22220

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/MoveForwardingReferenceCheck.cpp
  clang-tidy/misc/MoveForwardingReferenceCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-move-forwarding-reference.rst
  test/clang-tidy/misc-move-forwarding-reference.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22220.63513.patch
Type: text/x-patch
Size: 13380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160711/7fea78ba/attachment-0001.bin>


More information about the cfe-commits mailing list