Skip to content

Commit 359fd6c

Browse files
committed
Use IIFE so ReplacementText can be const.
on-behalf-of: @amd <[email protected]>
1 parent 969558e commit 359fd6c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,14 @@ void AvoidDefaultLambdaCaptureCheck::check(
6767
}
6868
}
6969

70-
// Replace with new capture list
71-
std::string ReplacementText;
72-
if (AllCaptures.empty()) {
73-
ReplacementText = "[]";
74-
} else {
75-
ReplacementText = "[" + llvm::join(AllCaptures, ", ") + "]";
76-
}
70+
const auto ReplacementText = [&AllCaptures]() -> std::string {
71+
if (AllCaptures.empty()) {
72+
return "[]";
73+
}
74+
return "[" + llvm::join(AllCaptures, ", ") + "]";
75+
}();
7776

78-
clang::SourceRange IntroducerRange = Lambda->getIntroducerRange();
77+
const clang::SourceRange IntroducerRange = Lambda->getIntroducerRange();
7978
if (IntroducerRange.isValid()) {
8079
Diag << clang::FixItHint::CreateReplacement(IntroducerRange,
8180
ReplacementText);

0 commit comments

Comments
 (0)