[clang-tools-extra] [clang-tidy] Add `AllowExplicitObjectParameters` option to `avoid-capturing-lambda-coroutines` (PR #182916)

Willem Kaufmann via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 3 05:22:18 PDT 2026


================
@@ -0,0 +1,93 @@
+// RUN: %check_clang_tidy -std=c++23 %s cppcoreguidelines-avoid-capturing-lambda-coroutines %t \
+// RUN:   -- -config='{CheckOptions: {cppcoreguidelines-avoid-capturing-lambda-coroutines.AllowExplicitObjectParameters: true}}' \
----------------
WillemKauf wrote:

Added a test case with 

```
// RUN: %check_clang_tidy -std=c++23-or-later -check-suffix=,CPP23 %s cppcoreguidelines-avoid-capturing-lambda-coroutines %t \
// RUN:   -- -config='{CheckOptions: {cppcoreguidelines-avoid-capturing-lambda-coroutines.AllowExplicitObjectParameters: false}}' \
// RUN:   -- -isystem %S/Inputs/system -DCPP23
```

with test case

```cpp
#ifdef CPP23
    [&v](this auto) -> task { co_return; };
    // CHECK-MESSAGES-CPP23: [[@LINE-1]]:5: warning: coroutine lambda may cause use-after-free, avoid captures or ensure lambda closure object has guaranteed lifetime [cppcoreguidelines-avoid-capturing-lambda-coroutines]
#endif

```

In the existing test file `avoid-capturing-lambda-coroutines.cpp`.

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


More information about the cfe-commits mailing list