Skip to content

[Clang][accepts-invalid] Clang accepts capturing const-qualified bit-fields by reference #124444

@zwuis

Description

@zwuis

Clang accepts this code:

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, 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 showing that capturing structured bindings refering bit-fields "means" capturing the bit-fields.

Compiler Explorer: https://godbolt.org/z/s8bY75Pqn

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partylambdaC++11 lambda expressions

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions