@@ -157,27 +157,28 @@ void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
157
157
.bind (" bad_owner_creation_parameter" ))),
158
158
this );
159
159
160
+ auto IsNotInSubLambda = stmt (
161
+ hasAncestor (
162
+ stmt (anyOf (equalsBoundNode (" body" ), lambdaExpr ())).bind (" scope" )),
163
+ hasAncestor (stmt (equalsBoundNode (" scope" ), equalsBoundNode (" body" ))));
164
+
160
165
// Matching on functions, that return an owner/resource, but don't declare
161
166
// their return type as owner.
162
167
Finder->addMatcher (
163
168
functionDecl (
164
169
decl ().bind (" function_decl" ),
165
- hasBody (stmt (
166
- stmt ().bind (" body" ),
167
- hasDescendant (
168
- returnStmt (hasReturnValue (ConsideredOwner),
169
- // Ignore sub-lambda expressions
170
- hasAncestor (stmt (anyOf (equalsBoundNode (" body" ),
171
- lambdaExpr ()))
172
- .bind (" scope" )),
173
- hasAncestor (stmt (equalsBoundNode (" scope" ),
174
- equalsBoundNode (" body" ))),
175
- // Ignore sub-functions
176
- hasAncestor (functionDecl ().bind (" context" )),
177
- hasAncestor (functionDecl (
178
- equalsBoundNode (" context" ),
179
- equalsBoundNode (" function_decl" ))))
180
- .bind (" bad_owner_return" )))),
170
+ hasBody (
171
+ stmt (stmt ().bind (" body" ),
172
+ hasDescendant (
173
+ returnStmt (hasReturnValue (ConsideredOwner),
174
+ // Ignore sub-lambda expressions
175
+ IsNotInSubLambda,
176
+ // Ignore sub-functions
177
+ hasAncestor (functionDecl ().bind (" context" )),
178
+ hasAncestor (functionDecl (
179
+ equalsBoundNode (" context" ),
180
+ equalsBoundNode (" function_decl" ))))
181
+ .bind (" bad_owner_return" )))),
181
182
returns (qualType (unless (hasDeclaration (OwnerDecl))).bind (" result" ))),
182
183
this );
183
184
@@ -186,22 +187,18 @@ void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
186
187
Finder->addMatcher (
187
188
lambdaExpr (
188
189
hasAncestor (decl (ScopeDeclaration).bind (" scope-decl" )),
189
- hasLambdaBody (stmt (
190
- stmt ().bind (" body" ),
191
- hasDescendant (
192
- returnStmt (
193
- hasReturnValue (ConsideredOwner),
194
- // Ignore sub-lambdas
195
- hasAncestor (
196
- stmt (anyOf (equalsBoundNode (" body" ), lambdaExpr ()))
197
- .bind (" scope" )),
198
- hasAncestor (stmt (equalsBoundNode (" scope" ),
199
- equalsBoundNode (" body" ))),
200
- // Ignore sub-functions
201
- hasAncestor (decl (ScopeDeclaration).bind (" context" )),
202
- hasAncestor (decl (equalsBoundNode (" context" ),
203
- equalsBoundNode (" scope-decl" ))))
204
- .bind (" bad_owner_return" )))),
190
+ hasLambdaBody (
191
+ stmt (stmt ().bind (" body" ),
192
+ hasDescendant (
193
+ returnStmt (
194
+ hasReturnValue (ConsideredOwner),
195
+ // Ignore sub-lambdas
196
+ IsNotInSubLambda,
197
+ // Ignore sub-functions
198
+ hasAncestor (decl (ScopeDeclaration).bind (" context" )),
199
+ hasAncestor (decl (equalsBoundNode (" context" ),
200
+ equalsBoundNode (" scope-decl" ))))
201
+ .bind (" bad_owner_return" )))),
205
202
hasCallOperator (returns (
206
203
qualType (unless (hasDeclaration (OwnerDecl))).bind (" result" ))))
207
204
.bind (" lambda" ),
0 commit comments