[clang] [clang-tools-extra] [clang-tidy] Add readability-avoid-default-lambda-capture (PR #160150)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 9 11:55:30 PDT 2025


================
@@ -0,0 +1,57 @@
+.. title:: clang-tidy - readability-avoid-default-lambda-capture
+
+readability-avoid-default-lambda-capture
+========================================
+
+Warns on default lambda captures (e.g. ``[&](){ ... }``, ``[=](){ ... }``).
+  
+Captures can lead to subtle bugs including dangling references and unnecessary
+copies. Writing out the name of the variables being captured reminds programmers
+and reviewers to know what is being captured. And knowing is half the battle.
+
+This check does not lint for variable-length array (VLA) captures. VLAs are not
----------------
vbvictor wrote:

```suggestion
This check does not warn on variable-length array (VLA) captures. VLAs are not
```

https://github.com/llvm/llvm-project/pull/160150


More information about the cfe-commits mailing list