[clang-tools-extra] [clang-tidy] Add readability-default-lambda-capture (PR #160150)
JJ Marr via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 25 08:29:23 PDT 2025
================
@@ -0,0 +1,98 @@
+// RUN: %check_clang_tidy %s readability-avoid-default-lambda-capture %t
+
+void test_default_captures() {
+ int value = 42;
+ int another = 10;
+
+ auto lambda1 = [=](int x) { return value + x; };
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are discouraged; prefer to capture specific variables explicitly [readability-avoid-default-lambda-capture]
+
+ auto lambda2 = [&](int x) { return value + x; };
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are discouraged; prefer to capture specific variables explicitly [readability-avoid-default-lambda-capture]
+
+ auto lambda3 = [=, &another](int x) { return value + another + x; };
+ // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: lambda default captures are discouraged; prefer to capture specific variables explicitly [readability-avoid-default-lambda-capture]
+
+ auto lambda4 = [&, value](int x) { return value + another + x; };
----------------
jjmarr-amd wrote:
what happens if value comes before &
https://github.com/llvm/llvm-project/pull/160150
More information about the cfe-commits
mailing list