File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -14,17 +14,24 @@ using namespace clang::ast_matchers;
14
14
15
15
namespace clang ::tidy::bugprone {
16
16
17
+ namespace {
18
+ AST_MATCHER (LambdaExpr, hasDefaultCapture) {
19
+ return Node.getCaptureDefault () != LCD_None;
20
+ }
21
+
22
+ } // namespace
23
+
17
24
void DefaultLambdaCaptureCheck::registerMatchers (MatchFinder *Finder) {
18
- Finder->addMatcher (lambdaExpr ().bind (" lambda" ), this );
25
+ Finder->addMatcher (lambdaExpr (hasDefaultCapture () ).bind (" lambda" ), this );
19
26
}
20
27
21
28
void DefaultLambdaCaptureCheck::check (const MatchFinder::MatchResult &Result) {
22
29
const auto *Lambda = Result.Nodes .getNodeAs <LambdaExpr>(" lambda" );
23
30
if (!Lambda)
24
31
return ;
25
32
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
28
35
29
36
SourceLocation DefaultCaptureLoc = Lambda->getCaptureDefaultLoc ();
30
37
if (DefaultCaptureLoc.isInvalid ())
You can’t perform that action at this time.
0 commit comments