Currently clang warns on 'assigning' to an enum bit-field that can not accommodate all its enumerators - but not when such a bit-field is defined.
GCC warns at definition time (https://godbolt.org/z/sKescn) - which seems like a useful thing to do, given certain programmer's propensities for memcpying.
This patch warns when such enum bit-fields are defined - and warns on unnamed bit-fields too (is that the right thing to do here?) building on work done by @rnk here https://github.com/llvm/llvm-project/commit/329f24d6f6e733fcadfd1be7cd3b430d63047c2e
- add the check, modeled after Reid's check in his patch, into VerifyBitField (checks if the width expression is an ICE and it's a worthy type etc.) that gets called from CheckFieldDecl
Questions for reviewers:
- Should we be emitting such a warning for unnamed bitfields?
- When comparing an APSInt to an unsigned value - should i prefer using the overloaded operator (i.e. Value < BitsNeeded) or stick with BitsNeeded > Value.getZExtValue().