https://github.com/dingcyrus created 
https://github.com/llvm/llvm-project/pull/242976

Fixes #242802

The option's rationale says explicit object parameters are exempted "because 
the captures are moved into the coroutine frame, decoupling their lifetime from 
the lambda object". That only holds once the call operator has been invoked: 
for a by-value `this auto` the closure is copied into the frame *at the call*, 
so the lambda object must still be alive at that point. A receiver that keeps 
only a reference to the lambda and calls it later, such as a coroutine taking 
`F&&`, copies from a destroyed closure, and the matcher — 
`unless(hasDeducingThis())`, which exempts every lambda whose call operator 
`isExplicitObjectMemberFunction()` — stays silent about it when the option is 
on.

This documents the limitation instead of changing the heuristic. Narrowing the 
matcher to keep warning in that case would itself be heuristic; #221750 asks 
for that on the `this auto&` case.

Docs only, no code or test change. Checked the claim is not repeated elsewhere 
in clang-tools-extra, and verified the RST with a differential docutils parse 
of the file (no new warnings; the single Sphinx-directive error is 
pre-existing).

AI assistance was used for source analysis and local verification.


>From 27dfcff54bcf99404c646b8d14413684cf0dfb7c Mon Sep 17 00:00:00 2001
From: Cyrus Ding <[email protected]>
Date: Mon, 16 Nov 2026 14:50:29 +0800
Subject: [PATCH] [clang-tidy] Qualify the AllowExplicitObjectParameters
 rationale

The option's documentation says explicit object parameters are exempted
"because the captures are moved into the coroutine frame, decoupling their
lifetime from the lambda object". That guarantee only holds once the call
operator has been invoked: for a by-value "this auto" the closure is copied
into the frame at the call, so the lambda object must still be alive at that
point. A receiver that stores only a reference to the lambda and calls it
later, such as a coroutine taking "F&&", copies from a destroyed closure, and
the check stays silent about it when the option is on.

Document the limitation rather than change the heuristic; narrowing the
matcher to keep warning in that case would itself be heuristic and is what
#221750 asks for the "this auto&" case.

Fixes #242802

AI assistance was used for source analysis and local verification.

Co-Authored-By: Claude Code <[email protected]>
---
 .../avoid-capturing-lambda-coroutines.rst                  | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst
index f54b33c0a7de83..17c1ceb16a9a67 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-capturing-lambda-coroutines.rst
@@ -63,6 +63,13 @@ Options
   check, because the captures are moved into the coroutine frame, decoupling
   their lifetime from the lambda object.
 
+  This exemption is a heuristic. The closure object is copied into the frame
+  when the call operator is *invoked*, so the lambda object must still be alive
+  at that point. Code that keeps only a reference to the lambda and calls it
+  later, such as a coroutine that takes a forwarding reference ``F&&``, still
+  copies from a destroyed closure and is not made safe by an explicit object
+  parameter.
+
   Default is `false`.
 
   The example from above can be made safe and will pass this check with the

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to