Skip to content

Commit e9e0f9a

Browse files
committed
fix namespacing issues
on-behalf-of: @amd <[email protected]>
1 parent a9509f3 commit e9e0f9a

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

clang-tools-extra/clang-tidy/readability/AvoidDefaultLambdaCaptureCheck.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,18 @@
1111
#include "clang/Basic/Lambda.h"
1212
#include "clang/Lex/Lexer.h"
1313

14-
using namespace clang::ast_matchers;
15-
16-
namespace clang::tidy::readability {
14+
using namespace clang::tidy::readability;
1715

1816
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) {
2519
if (Capture.capturesThis()) {
26-
return Capture.getCaptureKind() == LCK_StarThis ? "*this" : "this";
20+
return Capture.getCaptureKind() == clang::LCK_StarThis ? "*this" : "this";
2721
}
2822

2923
if (Capture.capturesVariable()) {
3024
std::string Result;
31-
if (Capture.getCaptureKind() == LCK_ByRef) {
25+
if (Capture.getCaptureKind() == clang::LCK_ByRef) {
3226
Result += "&";
3327
}
3428
Result += Capture.getCapturedVar()->getName().str();
@@ -46,16 +40,21 @@ generateImplicitCaptureText(const LambdaCapture &Capture) {
4640

4741
} // namespace
4842

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);
5149
}
5250

5351
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");
5654
assert(Lambda);
5755

58-
const SourceLocation DefaultCaptureLoc = Lambda->getCaptureDefaultLoc();
56+
const clang::SourceLocation DefaultCaptureLoc =
57+
Lambda->getCaptureDefaultLoc();
5958
if (DefaultCaptureLoc.isInvalid())
6059
return;
6160

@@ -85,10 +84,9 @@ void AvoidDefaultLambdaCaptureCheck::check(
8584
ReplacementText = "[" + llvm::join(AllCaptures, ", ") + "]";
8685
}
8786

88-
SourceRange IntroducerRange = Lambda->getIntroducerRange();
87+
clang::SourceRange IntroducerRange = Lambda->getIntroducerRange();
8988
if (IntroducerRange.isValid()) {
90-
Diag << FixItHint::CreateReplacement(IntroducerRange, ReplacementText);
89+
Diag << clang::FixItHint::CreateReplacement(IntroducerRange,
90+
ReplacementText);
9191
}
9292
}
93-
94-
} // namespace clang::tidy::readability

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,6 +5096,20 @@ AST_MATCHER_P(LambdaCapture, capturesVar, internal::Matcher<ValueDecl>,
50965096
/// matches `[this]() { return cc; }`.
50975097
AST_MATCHER(LambdaCapture, capturesThis) { return Node.capturesThis(); }
50985098

5099+
/// Matches lambda expressions that have default capture modes.
5100+
///
5101+
/// Given
5102+
/// \code
5103+
/// auto l1 = [=]() {}; // matches
5104+
/// auto l2 = [&]() {}; // matches
5105+
/// auto l3 = []() {}; // does not match
5106+
/// \endcode
5107+
/// lambdaExpr(hasDefaultCapture())
5108+
/// matches l1 and l2, but not l3.
5109+
AST_MATCHER(LambdaExpr, hasDefaultCapture) {
5110+
return Node.getCaptureDefault() != LCD_None;
5111+
}
5112+
50995113
/// Matches a constructor call expression which uses list initialization.
51005114
AST_MATCHER(CXXConstructExpr, isListInitialization) {
51015115
return Node.isListInitialization();

0 commit comments

Comments
 (0)