Quuxplusone / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
https://p1144.godbolt.org/z/jf67zx5hq
Other
1 stars 2 forks source link

Captured structured binding is wrongly considered a bitfield #19

Open Quuxplusone opened 1 year ago

Quuxplusone commented 1 year ago

https://godbolt.org/z/xKo6dj7cc

struct S {
    unsigned short i:2;
};
int main() {
    auto [i] = S();
    (void) [i]() mutable { i = 42; };
}

The assignment i = 42 produces a bogus warning:

warning: implicit truncation from 'int' to bit-field changes value from 42 to 2 [-Wbitfield-constant-conversion]
    7 |     (void) [i]() mutable { i = 42; };
      |                              ^ ~~

But the i being assigned to is not a bitfield; it's the lambda's data member i (which is not a bitfield). The correct machine code is generated; only "SemaChecking.cpp" gets confused. Perhaps AnalyzeBitfieldAssignment should be guarded by a test of refersToBitField().