Issue 124444
Summary [Clang][accepts-invalid] Clang accepts capturing const-qualified bit-fields by reference
Labels clang
Assignees
Reporter zwuis
    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>
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to