[clang-tidy] Fix misc-move-const-arg for move-only types.
authorAlexander Kornienko <alexfh@google.com>
Fri, 5 May 2017 17:33:49 +0000 (17:33 +0000)
committerAlexander Kornienko <alexfh@google.com>
Fri, 5 May 2017 17:33:49 +0000 (17:33 +0000)
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

llvm-svn: 302261

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

index 058ad2b..c8ef942 100644 (file)
@@ -73,6 +73,12 @@ void MoveConstantArgumentCheck::check(const MatchFinder::MatchResult &Result) {
       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;
index 2db6820..096f2f9 100644 (file)
@@ -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));
+}