[clang-tools-extra] r302261 - [clang-tidy] Fix misc-move-const-arg for move-only types.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Fri May 5 10:33:50 PDT 2017


Author: alexfh
Date: Fri May  5 12:33:49 2017
New Revision: 302261

URL: http://llvm.org/viewvc/llvm-project?rev=302261&view=rev
Log:
[clang-tidy] Fix misc-move-const-arg for move-only types.

Summary: Fix misc-move-const-arg false positives on move-only types.

Reviewers: sbenza

Reviewed By: sbenza

Subscribers: xazax.hun, cfe-commits

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

Modified:
    clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp?rev=302261&r1=302260&r2=302261&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp Fri May  5 12:33:49 2017
@@ -73,6 +73,12 @@ void MoveConstantArgumentCheck::check(co
       Arg->getType().isTriviallyCopyableType(*Result.Context);
 
   if (IsConstArg || IsTriviallyCopyable) {
+    if (const CXXRecordDecl *R = Arg->getType()->getAsCXXRecordDecl()) {
+      for (const auto *Ctor : R->ctors()) {
+        if (Ctor->isCopyConstructor() && Ctor->isDeleted())
+          return;
+      }
+    }
     bool IsVariable = isa<DeclRefExpr>(Arg);
     const auto *Var =
         IsVariable ? dyn_cast<DeclRefExpr>(Arg)->getDecl() : nullptr;

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp?rev=302261&r1=302260&r2=302261&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-move-const-arg.cpp Fri May  5 12:33:49 2017
@@ -158,3 +158,16 @@ void moveToConstReferenceNegatives() {
   // a lambda that is, in turn, an argument to a macro.
   CALL([no_move_semantics] { M3(NoMoveSemantics, no_move_semantics); });
 }
+
+class MoveOnly {
+public:
+  MoveOnly(const MoveOnly &other) = delete;
+  MoveOnly &operator=(const MoveOnly &other) = delete;
+  MoveOnly(MoveOnly &&other) = default;
+  MoveOnly &operator=(MoveOnly &&other) = default;
+};
+template <class T>
+void Q(T);
+void moveOnlyNegatives(MoveOnly val) {
+  Q(std::move(val));
+}




More information about the cfe-commits mailing list