@@ -27,28 +27,11 @@ AST_MATCHER_P(QualType, hasCleanType, Matcher<QualType>, InnerMatcher) {
27
27
Finder, Builder);
28
28
}
29
29
30
- constexpr std::array<StringRef, 2 > NameList {
30
+ constexpr std::array<StringRef, 2 > MakeSmartPtrList {
31
31
" ::std::make_unique" ,
32
32
" ::std::make_shared" ,
33
33
};
34
34
35
- Matcher<Expr> constructFrom (Matcher<QualType> TypeMatcher,
36
- Matcher<Expr> ArgumentMatcher) {
37
- return expr (
38
- anyOf (
39
- // construct optional
40
- cxxConstructExpr (argumentCountIs (1U ), hasType (TypeMatcher),
41
- hasArgument (0U , ArgumentMatcher)),
42
- // known template methods in std
43
- callExpr (argumentCountIs (1 ),
44
- callee (functionDecl (
45
- matchers::matchesAnyListedName (NameList),
46
- hasTemplateArgument (0 , refersToType (TypeMatcher)))),
47
- hasArgument (0 , ArgumentMatcher))),
48
- unless (anyOf (hasAncestor (typeLoc ()),
49
- hasAncestor (expr (matchers::hasUnevaluatedContext ())))));
50
- }
51
-
52
35
} // namespace
53
36
54
37
OptionalValueConversionCheck::OptionalValueConversionCheck (
@@ -74,7 +57,7 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
74
57
auto EqualsBoundOptionalType =
75
58
qualType (hasCleanType (equalsBoundNode (" optional-type" )));
76
59
77
- auto OptionalDereferenceMatcher = callExpr (
60
+ auto OptionalDerefMatcherImpl = callExpr (
78
61
anyOf (
79
62
cxxOperatorCallExpr (hasOverloadedOperatorName (" *" ),
80
63
hasUnaryOperand (hasType (EqualsBoundOptionalType)))
@@ -88,11 +71,24 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
88
71
89
72
auto StdMoveCallMatcher =
90
73
callExpr (argumentCountIs (1 ), callee (functionDecl (hasName (" ::std::move" ))),
91
- hasArgument (0 , ignoringImpCasts (OptionalDereferenceMatcher)));
74
+ hasArgument (0 , ignoringImpCasts (OptionalDerefMatcherImpl)));
75
+ auto OptionalDerefMatcher =
76
+ ignoringImpCasts (anyOf (OptionalDerefMatcherImpl, StdMoveCallMatcher));
77
+
92
78
Finder->addMatcher (
93
- expr (constructFrom (BindOptionalType,
94
- ignoringImpCasts (anyOf (OptionalDereferenceMatcher,
95
- StdMoveCallMatcher))))
79
+ expr (anyOf (
80
+ // construct optional
81
+ cxxConstructExpr (argumentCountIs (1 ), hasType (BindOptionalType),
82
+ hasArgument (0 , OptionalDerefMatcher)),
83
+ // known template methods in std
84
+ callExpr (
85
+ argumentCountIs (1 ),
86
+ callee (functionDecl (
87
+ matchers::matchesAnyListedName (MakeSmartPtrList),
88
+ hasTemplateArgument (0 , refersToType (BindOptionalType)))),
89
+ hasArgument (0 , OptionalDerefMatcher))),
90
+ unless (anyOf (hasAncestor (typeLoc ()),
91
+ hasAncestor (expr (matchers::hasUnevaluatedContext ())))))
96
92
.bind (" expr" ),
97
93
this );
98
94
}
0 commit comments