Skip to content

Commit fc7d374

Browse files
committed
Remove duplicate
1 parent 2d6bb71 commit fc7d374

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/OwningMemoryCheck.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,28 @@ void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
157157
.bind("bad_owner_creation_parameter"))),
158158
this);
159159

160+
auto IsNotInSubLambda = stmt(
161+
hasAncestor(
162+
stmt(anyOf(equalsBoundNode("body"), lambdaExpr())).bind("scope")),
163+
hasAncestor(stmt(equalsBoundNode("scope"), equalsBoundNode("body"))));
164+
160165
// Matching on functions, that return an owner/resource, but don't declare
161166
// their return type as owner.
162167
Finder->addMatcher(
163168
functionDecl(
164169
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")))),
181182
returns(qualType(unless(hasDeclaration(OwnerDecl))).bind("result"))),
182183
this);
183184

@@ -186,22 +187,18 @@ void OwningMemoryCheck::registerMatchers(MatchFinder *Finder) {
186187
Finder->addMatcher(
187188
lambdaExpr(
188189
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")))),
205202
hasCallOperator(returns(
206203
qualType(unless(hasDeclaration(OwnerDecl))).bind("result"))))
207204
.bind("lambda"),

0 commit comments

Comments
 (0)