[clang-tidy]: fix false positive of cert-oop54-cpp check.
Summary:
It seems we need a different matcher for binary operator
in a template context.
Fixes this issue:
https://bugs.llvm.org/show_bug.cgi?id=44499
Reviewers: aaron.ballman, alexfh, hokein, njames93
Reviewed By: aaron.ballman
Subscribers: xazax.hun, cfe-commits
Tags: #clang, #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D76990
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
index f2de9fb..d91353e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnhandledSelfAssignmentCheck.cpp
@@ -40,9 +40,12 @@
// Self-check: Code compares something with 'this' pointer. We don't check
// whether it is actually the parameter what we compare.
- const auto HasNoSelfCheck = cxxMethodDecl(unless(
+ const auto HasNoSelfCheck = cxxMethodDecl(unless(anyOf(
hasDescendant(binaryOperator(hasAnyOperatorName("==", "!="),
- has(ignoringParenCasts(cxxThisExpr()))))));
+ has(ignoringParenCasts(cxxThisExpr())))),
+ hasDescendant(cxxOperatorCallExpr(
+ hasAnyOverloadedOperatorName("==", "!="), argumentCountIs(2),
+ has(ignoringParenCasts(cxxThisExpr())))))));
// Both copy-and-swap and copy-and-move method creates a copy first and
// assign it to 'this' with swap or move.