<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/95225>95225</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Capturing constant bit-field by reference is not a constant expression
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Fedr
</td>
</tr>
</table>
<pre>
This program:
```
struct U {
int i : 4;
};
constexpr int foo() {
const auto & [y] = U{5};
return [&]() { return y; }();
}
static_assert( foo() == 5 );
```
is accepted by GCC, but Clang rejects it with the error:
```
error: static assertion expression is not an integral constant expression
10 | static_assert( foo() == 5 );
| ^~~~~~~~~~
note: initializer of '[y]' is not a constant expression
6 | const auto & [y] = U{5};
| ^
note: in call to '[&]() {
```
Online demo: https://gcc.godbolt.org/z/Mqx1M9589
If one removes lambda expression then the compilation succeeds, meaning that error about `initializer of '[y]' is not a constant expression` is wrong.
The code is slightly modified version from: https://stackoverflow.com/q/78611419/7325599
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyclM2O2zYQx59mdBmsIVGWZB50WNtV0UPQS3IuKGkksaVIhxx54xz67AVl766dpgFSwqBpzgd__M-YKgQ9WqIaij0Ux0QtPDlfN9T7pHX9pf446YAn70avZsifIT1C-gxlevusPwP7pWP8hFDtrzuIiNoyaoT8GbeQ3_ahOr6v17lzNjB9OfnVf3AOxA6EfEy1OqFa2CGIEqHYX6A4IuRH_ATVvrhPi5548TY6gSihOL4nfDVdIN9jjFktD3B3ZIEV6-4PFQJ5BrG7h8uP8ewCH8IfRdEBVdfRianH9oK_Hg4gDtgujAej7Iie_qSOA2rGF80T8kRI3jv_Xyq_GvEKhlcw7SxG-SiEuNQBrWNUNspJo1fmKp6yfOf2pmyWIlQH_Nmr4jpiJBS__P06rjbrmCKltpq1MvoreXQDgqhuZQNRvWH-EA7L9YifboB7uG-ZsFPG4Jqm-k6HfFf4363RlrCn2cUkE_MpxCKJBkQzdt1mdH3rDG-cH0E0X0E0Hz5_yT7IYifvG-q3AZ0l9DS7MwU0am57dV88nmidsHPzSRu1FjcsXUfUh9g9Mymr7Yg8Kb42C6rWLYxQpv9f7zKN9hfv7Li55_24kvQUrcHocWJzwdn1etDU45n8Cj14N_9blsCq-8udyQ_GvWw6N4NoPoNoql2ZZdtMxmUuikLKpK_zXuZSJVRnVbbLZCZ3eTLV5bAtxSCLVFRDK2XR9jLdFp3q0rKioVSJrkUqtmmZiSzLRSE3Vb8Vssxk3-5Eu8sH2KY0K202xpznWJ1Eh7BQLQshisSolkxYHz4hLL3gagQh4jvo6xjz1C5jgG1qdODwnoU1G6oP6sSLj-V4E7XV_DRoMus_3tNAnmxHP1Q_Wbypv2kpzdPS3kSLh96-nk7exTcDRLOiBhDN9SrnWvwTAAD__xiOukw">