11
11
#include " clang/Basic/Lambda.h"
12
12
#include " clang/Lex/Lexer.h"
13
13
14
- using namespace clang ::ast_matchers;
15
-
16
- namespace clang ::tidy::readability {
14
+ using namespace clang ::tidy::readability;
17
15
18
16
namespace {
19
- AST_MATCHER (LambdaExpr, hasDefaultCapture) {
20
- return Node.getCaptureDefault () != LCD_None;
21
- }
22
-
23
- std::optional<std::string>
24
- generateImplicitCaptureText (const LambdaCapture &Capture) {
17
+ static std::optional<std::string>
18
+ generateImplicitCaptureText (const clang::LambdaCapture &Capture) {
25
19
if (Capture.capturesThis ()) {
26
- return Capture.getCaptureKind () == LCK_StarThis ? " *this" : " this" ;
20
+ return Capture.getCaptureKind () == clang:: LCK_StarThis ? " *this" : " this" ;
27
21
}
28
22
29
23
if (Capture.capturesVariable ()) {
30
24
std::string Result;
31
- if (Capture.getCaptureKind () == LCK_ByRef) {
25
+ if (Capture.getCaptureKind () == clang:: LCK_ByRef) {
32
26
Result += " &" ;
33
27
}
34
28
Result += Capture.getCapturedVar ()->getName ().str ();
@@ -46,16 +40,21 @@ generateImplicitCaptureText(const LambdaCapture &Capture) {
46
40
47
41
} // namespace
48
42
49
- void AvoidDefaultLambdaCaptureCheck::registerMatchers (MatchFinder *Finder) {
50
- Finder->addMatcher (lambdaExpr (hasDefaultCapture ()).bind (" lambda" ), this );
43
+ void AvoidDefaultLambdaCaptureCheck::registerMatchers (
44
+ clang::ast_matchers::MatchFinder *Finder) {
45
+ Finder->addMatcher (
46
+ clang::ast_matchers::lambdaExpr (clang::ast_matchers::hasDefaultCapture ())
47
+ .bind (" lambda" ),
48
+ this );
51
49
}
52
50
53
51
void AvoidDefaultLambdaCaptureCheck::check (
54
- const MatchFinder::MatchResult &Result) {
55
- const auto *Lambda = Result.Nodes .getNodeAs <LambdaExpr>(" lambda" );
52
+ const clang::ast_matchers:: MatchFinder::MatchResult &Result) {
53
+ const auto *Lambda = Result.Nodes .getNodeAs <clang:: LambdaExpr>(" lambda" );
56
54
assert (Lambda);
57
55
58
- const SourceLocation DefaultCaptureLoc = Lambda->getCaptureDefaultLoc ();
56
+ const clang::SourceLocation DefaultCaptureLoc =
57
+ Lambda->getCaptureDefaultLoc ();
59
58
if (DefaultCaptureLoc.isInvalid ())
60
59
return ;
61
60
@@ -85,10 +84,9 @@ void AvoidDefaultLambdaCaptureCheck::check(
85
84
ReplacementText = " [" + llvm::join (AllCaptures, " , " ) + " ]" ;
86
85
}
87
86
88
- SourceRange IntroducerRange = Lambda->getIntroducerRange ();
87
+ clang:: SourceRange IntroducerRange = Lambda->getIntroducerRange ();
89
88
if (IntroducerRange.isValid ()) {
90
- Diag << FixItHint::CreateReplacement (IntroducerRange, ReplacementText);
89
+ Diag << clang::FixItHint::CreateReplacement (IntroducerRange,
90
+ ReplacementText);
91
91
}
92
92
}
93
-
94
- } // namespace clang::tidy::readability
0 commit comments