[PATCH] D31160: [clang-tidy] Fix misc-move-const-arg for move-only types.

Alexander Kornienko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 5 09:28:50 PDT 2017


alexfh updated this revision to Diff 97971.
alexfh added a comment.
Herald added a subscriber: xazax.hun.

Rebased on HEAD.


https://reviews.llvm.org/D31160

Files:
  clang-tidy/misc/MoveConstantArgumentCheck.cpp
  test/clang-tidy/misc-move-const-arg.cpp


Index: test/clang-tidy/misc-move-const-arg.cpp
===================================================================
--- test/clang-tidy/misc-move-const-arg.cpp
+++ test/clang-tidy/misc-move-const-arg.cpp
@@ -158,3 +158,16 @@
   // 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));
+}
Index: clang-tidy/misc/MoveConstantArgumentCheck.cpp
===================================================================
--- clang-tidy/misc/MoveConstantArgumentCheck.cpp
+++ clang-tidy/misc/MoveConstantArgumentCheck.cpp
@@ -73,6 +73,12 @@
       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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31160.97971.patch
Type: text/x-patch
Size: 1387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170505/07a81018/attachment-0001.bin>


More information about the cfe-commits mailing list