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

    <tr>
        <th>Summary</th>
        <td>
            [clang++] Can not capture member of structured binding to lambda in constant evaluation.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Clang rejects following code while gcc compiles it.

https://godbolt.org/z/E3TcTq1hx

```cpp
struct bar {
    int x;
};

consteval int foo() {
    const auto [a] = bar{};

    return [=] {
        return a;
    }();
}

int main() {
    return foo();
}
```

Error message from clang:

```
<source>:14:12: error: call to consteval function 'foo' is not a constant expression
   14 | return foo();
      |            ^
<source>:9:16: note: read of non-constexpr variable '[a]' is not allowed in a constant expression
    9 | return a;
      |                ^
<source>:8:12: note: in call to '[=] {
    return a;
}.operator()()'
    8 |     return [=] {
      | ^~~~~
    9 |         return a;
      |         ~~~~~~~~~
   10 | }();
      |     ~~~
<source>:14:12: note: in call to 'foo()'
   14 | return foo();
      |            ^~~~~
<source>:6:16: note: declared here
    6 |     const auto [a] = bar{};
      |                ^
1 error generated.
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVcuSqzYQ_Zpm0zUuEE8vWHjG9i5VWdwfEFIbKyUkIgnfSRb-9pSA8diZR1KXokA2p49Ot45a3HvVG6IWymco9wmfwtm69jfl7O9cD1PSWflX-6K56dHRHySCx5PV2v5UpkdhJeHPs9KEvRAo7DAqTR5V2EC6g3R3DmH0kO-AHYEdeys7q8PGuh7Y8W9gx0P-Q_z4Mzu_LnCo0uUW4wjpzgc3iYAddwj1M6Q7RERlAr5CHn9CvV8H6U5Y4wNduJ4BJ2uBNcC2d4EzAvkULEL5zKHcI-T7yB4xd1QR7ChMzkQg5PsZeuO5-8yXmPhPJJhnfJc2k0U1A1fmg5yV4qb0Ie6tDgvHwTnrcCDveU94cnZAEVckFvaxbnGcv3g7OUGQHyDfZUV8MMh3SJEmDgTXGoPF95qdJiOCsgaB1bOiGpVHYwPyBcVNQHodHXmvrFlSyAqE-uWLRJY6xe93F5SHjwq3UWAVdRkbKL4dcYn2hMaap0Xj6-jwwp3inaaocV3Ae53RkyRRme8k4_ZeMv9G6pdym1s93-Qqc6voIu2DZR7ng3q_sSM5HqxbS7Y-6xXf3NR868MIgvJwvV6vD-l97dLHNK9v17qe6cL46OTHsAX8tcc-r8m7N95S_CXvXD-dvfrgH0lCc0cSz-Ro5atufP-vD_yHKbJlN2FPJi4kyc39Nkxkm8ttvuUJtVldFFlelmmVnFtZV7JJm4ZkU3fZqcrZtix5ecrrMitY0SWqZSkr0yJtsiYt02pTlZ3oBJeceFazpoMipYErvdH6MsROmijvJ2qzvGi2daJ5R9rP3ZyxpUkwFhu7a2PAUzf1HopUKx_8O0VQQc9HwBrxHO9yjy_czJtL8DFMjnCgoSMXt-bSmqdY5E4ZGQ-DYFHzoZN8XvzbDrxwPfHYWzbJ5HT7rxNBhfPUbYQdgB2jnPX1NDobDxtgxzk9D-y4Znhp2T8BAAD__1T64Vw">