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().
https://godbolt.org/z/xKo6dj7cc
The assignment
i = 42
produces a bogus warning:But the
i
being assigned to is not a bitfield; it's the lambda's data memberi
(which is not a bitfield). The correct machine code is generated; only "SemaChecking.cpp" gets confused. PerhapsAnalyzeBitfieldAssignment
should be guarded by a test ofrefersToBitField()
.