<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/76995>76995</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [[coro_lifetimebound]] does not catch lifetime issues with lambda captures
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            usx95
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          usx95
      </td>
    </tr>
</table>

<pre>
    The pattern of interest is 
```cpp
co_task<int> coro() {
    int a = 1;
    auto lamb = [a](int x, const int& y) -> co_task<int> {
        co_return x + y + a; // 'a' in the lambda object dies after the iniital_suspend.
    }(1, a);
 co_return co_await lamb;
}
```
https://godbolt.org/z/GWPEovWWc

Lambda captures (even by value) are prone to use after free once the lambda object dies. In the above example, it appears only as a temporary in the call expression.

It should be fine if this is used in a `co_await` expression. Example:

```cpp
co_task<int> coro() {
    int a = 1;
    int res = co_await [a](int x, const int& y) -> co_task<int> {
 co_return x + y + a;
    }(1, a);
    co_return res;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VEGPqzYQ_jXDZbQRMSHAgcPmZVM9qYceKu0xGpthcevYyDbZpL--MmSb7JO26qEPISPG42---fzZFIJ-s8wtlDsQYgqXpgQhoNxnNMXB-XYOZdJ11_b3gXGkGNlbdD1qG9lziKgDQr6H_Bm2-fKqcVwiyh0jhT-h-KZthOIFlfMORA2iQah2SxIiJjAkhGKPayge4jRFh4ZOcp6DckdQ7kHUKf8C4hsqZxMFG0Fs8Zpwn5Y6PxT-VC09yh09x8lbvCCIHV7nkaDYIYgDiAOCqAhEhdpiHHhm0RE6-QeriJ3mgNRH9vOktlpHMscwhZFtt7rXgirxXSeuBKK5d3cnoNyR3knHucQ_CWnhZ1mX3yHGMUDxvLB8c510Jq6cfwNx-AvE4ZfX317c-fVV3VbP468LeUVjnDwHBFHzmS3KK57JTJyEI884emcZo8Mp8K293jOjs4q_UGGF3xeBSLozI1_oNBpO_eqINI5MPqCz5ooUkDDyaXSe_PVDV0XGIF9GzyFoZ1ePtL9HDIObTIeSsdeWUfcYBx2S6abAXQIhTJa7aQjb_BEMX250iudH3J_g1BSflS329w39Xwz7tVP_g8s-Od1z-Bd7ZV1bdE3RUMbtuso3RVMLIbKhZa6FkL3oqrzr63KzrqXMqdtWqiOSG8p0K3Kxydf5Zt2UVS5WfSk2vFZKkqpUrmrY5HwibVbGnE_Jq5kOYeK22jZNmRmSbMLtDrL8jvPk7R7ybVrzJKe3AJvc6BDDHSXqaJbLq9ylDTsa3XPUJ5Zusl1Svtxj5zigdREVRTXgR8pSJeC7jsOHrT_ORzZ50_5w0HQcJrlS7gTikAjcPk-jd-ksgDgsgCAOc1t_BwAA__-umZve">