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

    <tr>
        <th>Summary</th>
        <td>
            Errors capturing structured bindings in generic lambda with arguments
        </td>
    </tr>

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

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

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

<pre>
    ```cpp
struct Foo {
    int first;
    int second;
};

void bar() {
    Foo f;
    auto &[first, second] = f;
    auto works1 = [&first]() { (void) first; };
    auto works2 = [&]() { (void) first; };
    auto bug1 = [&first](auto arg) { (void) first; }; // -Wunused-lambda-capture
    auto bug2 = [&](auto arg) { (void) first; }; // error: reference to local binding 'first' declared in enclosing function 'bar'
    works1();
    works2();
    bug1(42);
    bug2(42);
}
```
https://godbolt.org/z/zzqdf9sa8

When a generic lambda attempts to capture a structured binding (legal since c++20), clang either emits an `unused-lambda-capture` warning for explicit structured binding captures, or it fails to compile if the structured binding is used in a generic lambda with an implicit default capture.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydU9tymzAQ_Rp40dgDko3NAw9JXf9CnoW0YKVCorrEbb6-K7DrOKbTaRmwJe3lnD27aq382WRVMb9iHLPikBVPPrgoAjlaS7Ld83xG8FEmkE45HzL26dSDsEb-Ps52h9t6-n2zSpKWu4zuM1rfp0043V1KHgNC0yrbPs949MsVYnsgGTss-Z-t--bLyYpxGD2Hbg83TMy5T0zS9loI-Uj2Phn9kOw_87Sx_wOlycxd__eUaDriS1Yv0UQPcqX50Eq-EnwM0cEj4iPvfwcD56zL2BNx0IEDI4BgCm0F16RVRirTo-vu0p4dkSA0dyBxHAh6a-uTRxeNCMqa5Dp1f3djO_drFvVOuFn7BUMSE483dMFAHwypnnlxHfB5ewph9FjZXGhvZWt1WNskzvE9fe_fZVd7vv84vy8nMISTHgw4JcjcAcJDgGEMPklz6QY6zdcnJjFuSu019CgdqoJKioxib55pkfjibKN06AQqnMARGBRm5KhZVSw3vCrImTszCWwx4MeolVBhCfgS4hMKuqJTx5WeCdthVBqI6gjiLgUrTxJ8aulD6Wckm0iq4QIuoeNRhyviOoemrKqqYOWmYrlsmKxZzfOggobma5ouf_FNUI_oPsEugro-DmCCz6PTzaduokNs11gabrR-u_6tRmdfQeCkHpX3Melx3OK8FPmp6bq27hgDRmu6B8FqBttNVdZImLdV0eaat6B9M90nauBMphS4xruVq4YWlJZFuSv3rCzYuuxKWgnBOYeyrHmVbQoYUPN14pHGLHfNRAmH1qNRKx_8zci9V70BmOAwP97ck3XNq3Q2nriT-QTeTOR_AeHgu_s">