@@ -49,29 +49,41 @@ internal::Matcher<Decl> knownSmartptr() {
4949
5050void registerMatchersForGetArrowStart (MatchFinder *Finder,
5151 MatchFinder::MatchCallback *Callback) {
52- const auto QuacksLikeASmartptr = recordDecl (
53- recordDecl ().bind (" duck_typing" ),
54- has (cxxMethodDecl (hasName (" operator->" ),
55- returns (qualType (pointsTo (type ().bind (" op->Type" )))))),
56- has (cxxMethodDecl (hasName (" operator*" ), returns (qualType (references (
57- type ().bind (" op*Type" )))))));
52+ const auto MatchesOpArrow =
53+ allOf (hasName (" operator->" ),
54+ returns (qualType (pointsTo (type ().bind (" op->Type" )))));
55+ const auto MatchesOpStar =
56+ allOf (hasName (" operator*" ),
57+ returns (qualType (references (type ().bind (" op*Type" )))));
58+ const auto HasRelevantOps =
59+ allOf (anyOf (hasMethod (MatchesOpArrow),
60+ has (functionTemplateDecl (has (functionDecl (MatchesOpArrow))))),
61+ anyOf (hasMethod (MatchesOpStar),
62+ has (functionTemplateDecl (has (functionDecl (MatchesOpStar))))));
63+
64+ const auto QuacksLikeASmartptr =
65+ cxxRecordDecl (cxxRecordDecl ().bind (" duck_typing" ), HasRelevantOps);
5866
5967 // Make sure we are not missing the known standard types.
60- const auto Smartptr = anyOf (knownSmartptr (), QuacksLikeASmartptr);
68+ const auto SmartptrAny = anyOf (knownSmartptr (), QuacksLikeASmartptr);
69+ const auto SmartptrWithDeref =
70+ anyOf (cxxRecordDecl (knownSmartptr (), HasRelevantOps), QuacksLikeASmartptr);
6171
6272 // Catch 'ptr.get()->Foo()'
63- Finder->addMatcher (memberExpr (expr ().bind (" memberExpr" ), isArrow (),
64- hasObjectExpression (callToGet (Smartptr))),
65- Callback);
73+ Finder->addMatcher (
74+ memberExpr (expr ().bind (" memberExpr" ), isArrow (),
75+ hasObjectExpression (callToGet (SmartptrWithDeref))),
76+ Callback);
6677
6778 // Catch '*ptr.get()' or '*ptr->get()'
6879 Finder->addMatcher (
69- unaryOperator (hasOperatorName (" *" ), hasUnaryOperand (callToGet (Smartptr))),
80+ unaryOperator (hasOperatorName (" *" ),
81+ hasUnaryOperand (callToGet (SmartptrWithDeref))),
7082 Callback);
7183
7284 // Catch '!ptr.get()'
7385 const auto CallToGetAsBool = callToGet (
74- recordDecl (Smartptr , has (cxxConversionDecl (returns (booleanType ())))));
86+ recordDecl (SmartptrAny , has (cxxConversionDecl (returns (booleanType ())))));
7587 Finder->addMatcher (
7688 unaryOperator (hasOperatorName (" !" ), hasUnaryOperand (CallToGetAsBool)),
7789 Callback);
@@ -84,7 +96,7 @@ void registerMatchersForGetArrowStart(MatchFinder *Finder,
8496 Callback);
8597
8698 Finder->addMatcher (cxxDependentScopeMemberExpr (hasObjectExpression (
87- callExpr (has (callToGet (Smartptr))). bind ( " obj " ))),
99+ callExpr (has (callToGet (SmartptrAny)) ))),
88100 Callback);
89101}
90102
0 commit comments