Skip to content

Commit 9765c90

Browse files
committed
Turns out this check doesn't like templated lambdas
on-behalf-of: @amd <[email protected]>
1 parent 4e10e78 commit 9765c90

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ void AvoidDefaultLambdaCaptureCheck::check(
5454
ImplicitCaptures.push_back(generateCaptureText(Capture));
5555
}
5656

57+
// For template-dependent lambdas, the list of captures hasn't been created
58+
// yet, so the list of implicit captures is empty.
59+
if (ImplicitCaptures.empty() && Lambda->isGenericLambda())
60+
return;
61+
5762
const auto ReplacementText = [&ImplicitCaptures]() {
5863
return llvm::join(ImplicitCaptures, ", ");
5964
}();

clang-tools-extra/test/clang-tidy/checkers/readability/avoid-default-lambda-capture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ class TestClass {
9595
}
9696
};
9797

98+
// Lambda captures dependent on a template parameter don't have a fix it
9899
template<typename T>
99100
void test_template_lambdas() {
100101
T value{};
101102

102103
auto lambda = [=](T x) { return value + x; };
103104
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: lambda default captures are discouraged; prefer to capture specific variables explicitly [readability-avoid-default-lambda-capture]
104-
// CHECK-FIXES: auto lambda = [value](T x) { return value + x; };
105105
}
106106

107107
void instantiate_templates() {

0 commit comments

Comments
 (0)