Skip to content

Commit db17a4c

Browse files
committed
add new matcher
on-behalf-of: @amd <[email protected]>
1 parent 9991b9c commit db17a4c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

clang-tools-extra/clang-tidy/bugprone/DefaultLambdaCaptureCheck.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,24 @@ using namespace clang::ast_matchers;
1414

1515
namespace clang::tidy::bugprone {
1616

17+
namespace {
18+
AST_MATCHER(LambdaExpr, hasDefaultCapture) {
19+
return Node.getCaptureDefault() != LCD_None;
20+
}
21+
22+
} // namespace
23+
1724
void DefaultLambdaCaptureCheck::registerMatchers(MatchFinder *Finder) {
18-
Finder->addMatcher(lambdaExpr().bind("lambda"), this);
25+
Finder->addMatcher(lambdaExpr(hasDefaultCapture()).bind("lambda"), this);
1926
}
2027

2128
void DefaultLambdaCaptureCheck::check(const MatchFinder::MatchResult &Result) {
2229
const auto *Lambda = Result.Nodes.getNodeAs<LambdaExpr>("lambda");
2330
if (!Lambda)
2431
return;
2532

26-
if (Lambda->getCaptureDefault() == LCD_None)
27-
return;
33+
// No need to check getCaptureDefault() != LCD_None since our custom matcher
34+
// hasDefaultCapture() already ensures this condition
2835

2936
SourceLocation DefaultCaptureLoc = Lambda->getCaptureDefaultLoc();
3037
if (DefaultCaptureLoc.isInvalid())

0 commit comments

Comments
 (0)