summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Berger <flx@google.com>2017-01-19 15:51:10 +0000
committerFelix Berger <flx@google.com>2017-01-19 15:51:10 +0000
commit08df2464073f32c997c3ab39b6a3944a75923884 (patch)
tree6a4649da7f21573d8d099ade9fc0f3bf44e9e408
parentc3cb054e0cb030f447a1cf1fee2249ebc7e7b299 (diff)
downloadbcm5719-llvm-08df2464073f32c997c3ab39b6a3944a75923884.tar.gz
bcm5719-llvm-08df2464073f32c997c3ab39b6a3944a75923884.zip
[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
-rw-r--r--clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp3
-rw-r--r--clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp11
2 files changed, 13 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
index a28b1d25a04..06acd310170 100644
--- a/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/DeclRefExprUtils.cpp
@@ -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();
diff --git a/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp b/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp
index cf12d2ccd8c..dfd545ab2b7 100644
--- a/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp
+++ b/clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -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
OpenPOWER on IntegriCloud