@@ -43,10 +43,18 @@ internal::Matcher<Expr> callToGet(const internal::Matcher<Decl> &OnClass) {
43
43
.bind (" redundant_get" );
44
44
}
45
45
46
- internal::Matcher<Decl> knownSmartptr () {
46
+ internal::Matcher<Decl> knownSmartptrAny () {
47
47
return recordDecl (hasAnyName (" ::std::unique_ptr" , " ::std::shared_ptr" ));
48
48
}
49
49
50
+ internal::Matcher<Decl> knownSmartptrNonArray () {
51
+ return recordDecl (hasAnyName (" ::std::unique_ptr" , " ::std::shared_ptr" ),
52
+ anyOf (has (cxxMethodDecl (hasName (" operator*" ))),
53
+ has (functionTemplateDecl (hasName (" operator*" )))),
54
+ anyOf (has (cxxMethodDecl (hasName (" operator->" ))),
55
+ has (functionTemplateDecl (hasName (" operator->" )))));
56
+ }
57
+
50
58
void registerMatchersForGetArrowStart (MatchFinder *Finder,
51
59
MatchFinder::MatchCallback *Callback) {
52
60
const auto QuacksLikeASmartptr = recordDecl (
@@ -57,21 +65,25 @@ void registerMatchersForGetArrowStart(MatchFinder *Finder,
57
65
type ().bind (" op*Type" )))))));
58
66
59
67
// Make sure we are not missing the known standard types.
60
- const auto Smartptr = anyOf (knownSmartptr (), QuacksLikeASmartptr);
68
+ const auto SmartptrAny = anyOf (knownSmartptrAny (), QuacksLikeASmartptr);
69
+ const auto SmartptrNonArray =
70
+ anyOf (knownSmartptrNonArray (), QuacksLikeASmartptr);
61
71
62
72
// 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 (SmartptrNonArray))),
76
+ Callback);
66
77
67
78
// Catch '*ptr.get()' or '*ptr->get()'
68
79
Finder->addMatcher (
69
- unaryOperator (hasOperatorName (" *" ), hasUnaryOperand (callToGet (Smartptr))),
80
+ unaryOperator (hasOperatorName (" *" ),
81
+ hasUnaryOperand (callToGet (SmartptrNonArray))),
70
82
Callback);
71
83
72
84
// Catch '!ptr.get()'
73
85
const auto CallToGetAsBool = callToGet (
74
- recordDecl (Smartptr , has (cxxConversionDecl (returns (booleanType ())))));
86
+ recordDecl (SmartptrAny , has (cxxConversionDecl (returns (booleanType ())))));
75
87
Finder->addMatcher (
76
88
unaryOperator (hasOperatorName (" !" ), hasUnaryOperand (CallToGetAsBool)),
77
89
Callback);
@@ -84,7 +96,7 @@ void registerMatchersForGetArrowStart(MatchFinder *Finder,
84
96
Callback);
85
97
86
98
Finder->addMatcher (cxxDependentScopeMemberExpr (hasObjectExpression (
87
- callExpr (has (callToGet (Smartptr))). bind ( " obj " ))),
99
+ callExpr (has (callToGet (SmartptrAny)) ))),
88
100
Callback);
89
101
}
90
102
@@ -100,7 +112,7 @@ void registerMatchersForGetEquals(MatchFinder *Finder,
100
112
binaryOperator (hasAnyOperatorName (" ==" , " !=" ),
101
113
hasOperands (anyOf (cxxNullPtrLiteralExpr (), gnuNullExpr (),
102
114
integerLiteral (equals (0 ))),
103
- callToGet (knownSmartptr ()))),
115
+ callToGet (knownSmartptrAny ()))),
104
116
Callback);
105
117
106
118
// FIXME: Match and fix if (l.get() == r.get()).
0 commit comments