@@ -30,6 +30,10 @@ internal::Matcher<Expr> callToGet(const internal::Matcher<Decl> &OnClass) {
30
30
.bind (" redundant_get" );
31
31
}
32
32
33
+ internal::Matcher<Decl> knownSmartptr () {
34
+ return recordDecl (hasAnyName (" ::std::unique_ptr" , " ::std::shared_ptr" ));
35
+ }
36
+
33
37
void registerMatchersForGetArrowStart (MatchFinder *Finder,
34
38
MatchFinder::MatchCallback *Callback) {
35
39
const auto QuacksLikeASmartptr = recordDecl (
@@ -39,21 +43,23 @@ void registerMatchersForGetArrowStart(MatchFinder *Finder,
39
43
has (cxxMethodDecl (hasName (" operator*" ), returns (qualType (references (
40
44
type ().bind (" op*Type" )))))));
41
45
46
+ // Make sure we are not missing the known standard types.
47
+ const auto Smartptr = anyOf (knownSmartptr (), QuacksLikeASmartptr);
48
+
42
49
// Catch 'ptr.get()->Foo()'
43
- Finder->addMatcher (memberExpr ( expr (). bind ( " memberExpr " ), isArrow (),
44
- hasObjectExpression ( ignoringImpCasts (
45
- callToGet (QuacksLikeASmartptr )))),
46
- Callback);
50
+ Finder->addMatcher (
51
+ memberExpr ( expr (). bind ( " memberExpr " ), isArrow (),
52
+ hasObjectExpression ( ignoringImpCasts ( callToGet (Smartptr )))),
53
+ Callback);
47
54
48
55
// Catch '*ptr.get()' or '*ptr->get()'
49
56
Finder->addMatcher (
50
- unaryOperator (hasOperatorName (" *" ),
51
- hasUnaryOperand (callToGet (QuacksLikeASmartptr))),
57
+ unaryOperator (hasOperatorName (" *" ), hasUnaryOperand (callToGet (Smartptr))),
52
58
Callback);
53
59
54
60
// Catch '!ptr.get()'
55
- const auto CallToGetAsBool = ignoringParenImpCasts (callToGet (recordDecl (
56
- QuacksLikeASmartptr , has (cxxConversionDecl (returns (booleanType ()))))));
61
+ const auto CallToGetAsBool = ignoringParenImpCasts (callToGet (
62
+ recordDecl (Smartptr , has (cxxConversionDecl (returns (booleanType ()))))));
57
63
Finder->addMatcher (
58
64
unaryOperator (hasOperatorName (" !" ), hasUnaryOperand (CallToGetAsBool)),
59
65
Callback);
@@ -71,18 +77,15 @@ void registerMatchersForGetEquals(MatchFinder *Finder,
71
77
// This one is harder to do with duck typing.
72
78
// The operator==/!= that we are looking for might be member or non-member,
73
79
// might be on global namespace or found by ADL, might be a template, etc.
74
- // For now, lets keep a list of known standard types.
75
-
76
- const auto IsAKnownSmartptr =
77
- recordDecl (hasAnyName (" ::std::unique_ptr" , " ::std::shared_ptr" ));
80
+ // For now, lets keep it to the known standard types.
78
81
79
82
// Matches against nullptr.
80
83
Finder->addMatcher (
81
84
binaryOperator (anyOf (hasOperatorName (" ==" ), hasOperatorName (" !=" )),
82
85
hasEitherOperand (ignoringImpCasts (
83
86
anyOf (cxxNullPtrLiteralExpr (), gnuNullExpr (),
84
87
integerLiteral (equals (0 ))))),
85
- hasEitherOperand (callToGet (IsAKnownSmartptr ))),
88
+ hasEitherOperand (callToGet (knownSmartptr () ))),
86
89
Callback);
87
90
88
91
// FIXME: Match and fix if (l.get() == r.get()).
0 commit comments