22 MatchFinder *Finder) {
23 const auto MemberExprOrSourceObject = anyOf(
25 declRefExpr(to(decl(equalsBoundNode(std::string(
SourceDeclName))))));
27 const auto IsPartOfSource =
28 allOf(unless(hasDescendant(expr(unless(MemberExprOrSourceObject)))),
29 MemberExprOrSourceObject);
31 const auto IsSourceMutatingAssignment = traverse(
32 TK_AsIs, binaryOperation(hasOperatorName(
"="), hasLHS(IsPartOfSource))
35 const auto MemberExprOrSelf = anyOf(memberExpr(), cxxThisExpr());
37 const auto IsPartOfSelf = allOf(
38 unless(hasDescendant(expr(unless(MemberExprOrSelf)))), MemberExprOrSelf);
40 const auto IsSelfMutatingAssignment =
41 binaryOperation(isAssignmentOperator(), hasLHS(IsPartOfSelf));
43 const auto IsSelfMutatingMemberFunction =
44 functionDecl(hasBody(hasDescendant(IsSelfMutatingAssignment)));
46 const auto IsSourceMutatingMemberCall =
47 cxxMemberCallExpr(on(IsPartOfSource),
48 callee(IsSelfMutatingMemberFunction))
51 const auto MutatesSource = allOf(
53 0, parmVarDecl(hasType(lValueReferenceType())).bind(
SourceDeclName)),
54 anyOf(forEachDescendant(IsSourceMutatingAssignment),
55 forEachDescendant(IsSourceMutatingMemberCall)));
57 Finder->addMatcher(cxxConstructorDecl(isCopyConstructor(), MutatesSource),
60 Finder->addMatcher(cxxMethodDecl(isCopyAssignmentOperator(), MutatesSource),