<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/124444>124444</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang][accepts-invalid] Clang accepts capturing const-qualified bit-fields by reference
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
zwuis
</td>
</tr>
</table>
<pre>
Clang accepts this code:
```cpp
void test1() {
struct S { int a : 4; };
const auto [x] = S{};
[&x] {}(); // #1
[&] { (void)x; }(); // #2
}
void test2() {
struct S { const int a : 4; };
auto [x] = S{};
[&x] {}(); // #3
[&] { (void)x; }(); // #4
}
```
According to [[expr.prim.lambda.capture]/12](https://eel.is/c++draft/expr.prim.lambda.capture#12.sentence-4), all of these 4 cases should be ill-formed:
> ... A bit-field or a member of an anonymous union shall not be captured by reference.
You can see examples in [P1381R1](https://wg21.link/P1381R1#what-can-we-do) showing that capturing structured bindings refering bit-fields "means" capturing the bit-fields.
Compiler Explorer: <https://godbolt.org/z/s8bY75Pqn>
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysVEuPnDgQ_jXFpQSCAhr6wKEf0-doc8rRmKLxrrEJNtM9-fUrQ88jo6xy2EhIFvZXVd9XL-GcuhrmBsojlOdILH6wc_PjtigXtbZ7aU5amCsKKXnyDv2gHErbMeQHSNdvl26fnCZID89WdejZ-QyoBtojVMeAOhEcUnR-XqTHr-EWlfEoEPIDFpAfEaoz5B-w0hrnUSzeIpTHO5RnhPyMX4PDT9BAnnYbZHtdY69e6QJ0QaA8-4x_wBGoDqyB9vdXHr8wp2BenTfRbyrptyo3Gb_R-udU5v9PZfGu8rWum-KDlHbulLnixhTKI9-nOZlmNSZajG0nEikmv8wM5RnoktF61oP3kwvdssZg1olyQBcJdAQ6drPofbj_L1-UZ5Q4Np6N5LgIhOmEQmu0PfqBHWOBUjh26Aa76A5bRqV13Nt55O69TfMnTJIED9gqH_eKdYd2RoEjjy3PwZswKIw1L6NdHC5GWYNuCJGM9cHrg1KH7QvO3PMcKCWb-292QSkMOmbkuxgnzQ6VCZn6kuV19lf2q2zcrpQlWpl_gC6vMMpvg_CxFCa-cdzZ0F1usLc19YPwDxrhd-uzjZIyoThuIxYe32Q6BKKRhXFA9MHaD_wB9NBxsuOkNM_4dJ-0nXkOLQv56WfeV9u1VvvEzlegyw-gi6vbb1X55buB_Cnqmrzb53sRcZNVeVXv6rraRUNTSVnXWZbtqez7XSXLnKkrc7Hfy7Sq-yxSDaVUphnt0pKybJdk1Nct7agtZdmLooci5VEonWj9PIbwkXJu4SajoiiKSIuWtVt3GZEMiwsotGE0N8EgbpergyLVynn37sIrr9cFuK66UKfy-Nh3sTLPQqsuDNHPi_A9j-uAx98XoVWv1lK8Jf5jo0TLrJtPaVR-WNpE2hHoEug8jnia7d8sw1ys8tw6TqvC54b-DQAA__-I2ar3">