Skip to content

Commit

Permalink
[clang-tidy] Fix misc-move-const-arg for move-only types.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexfh committed May 5, 2017
1 parent f88bf5a commit b489867
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions clang-tools-extra/test/clang-tidy/misc-move-const-arg.cpp
Expand Up @@ -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));
}

0 comments on commit b489867

Please sign in to comment.