[clang-tidy] Do not trigger move fix for non-copy assignment operators in performance-unnecessary-value-param check

Reviewers: alexfh, sbenza, malcolm.parsons

Subscribers: JDevlieghere, cfe-commits

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

llvm-svn: 292491
This commit is contained in:
Felix Berger 2017-01-19 15:51:10 +00:00
parent c3cb054e0c
commit 08df246407
2 changed files with 13 additions and 1 deletions

View File

@ -159,7 +159,8 @@ bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Decl &Decl,
parmVarDecl(hasType(matchers::isReferenceToConst())));
auto Matches = match(
decl(hasDescendant(
cxxOperatorCallExpr(UsedAsConstRefArg, hasOverloadedOperatorName("="))
cxxOperatorCallExpr(UsedAsConstRefArg, hasOverloadedOperatorName("="),
callee(cxxMethodDecl(isCopyAssignmentOperator())))
.bind("operatorCallExpr"))),
Decl, Context);
return !Matches.empty();

View File

@ -247,6 +247,17 @@ void PositiveMoveOnCopyAssignment(ExpensiveMovableType E) {
// CHECK-FIXES: F = std::move(E);
}
struct NotCopyAssigned {
NotCopyAssigned &operator=(const ExpensiveMovableType &);
};
void PositiveNoMoveForNonCopyAssigmentOperator(ExpensiveMovableType E) {
// CHECK-MESSAGES: [[@LINE-1]]:69: warning: the parameter 'E' is copied
// CHECK-FIXES: void PositiveNoMoveForNonCopyAssigmentOperator(const ExpensiveMovableType& E) {
NotCopyAssigned N;
N = E;
}
// The argument could be moved but is not since copy statement is inside a loop.
void PositiveNoMoveInsideLoop(ExpensiveMovableType E) {
// CHECK-MESSAGES: [[@LINE-1]]:52: warning: the parameter 'E' is copied