https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118667

            Bug ID: 118667
           Summary: lambda references to bit-fields via structure binding
                    is invalid
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, c++-lambda
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Forwarded from https://github.com/llvm/llvm-project/issues/124444 since GCC
also accepts it.

Take:
```
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
}
```

All 4 lines marked with #1 should be rejected as invalid as you cannot do a
lambda reference to a bitfield.
According to [expr.prim.lambda.capture]/12, 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.

Reply via email to