[clang] [Clang] Consider preferred_type in bitfield warnings (#116760) (PR #116785)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 16 13:28:51 PST 2025


ojhunt wrote:

> > This does mean that if the preferred and explicit types have different storage requirements we may not warn in all possible cases, but that's a scenario for which the warnings are much more complex and confusing
> 
> If I understand the patch correctly, we always warn, but about the wrong thing.
> 
> Should we pick the minimum of both sizes? Should we make it an error for a bit-field to be _larger_ than the prefered type?

I've done a bunch of messing around, the error handling and semantics become super terrible pretty quickly.

I think these semantics work for the general use case - "it's an integer actually containing an enum" - even though it could be an enum type with a different enum type as the preferred type.

I think a follow on patch should add gcc like semantics where we just warn at the declaration, and then it becomes much easier to say "the preferred and real type must both fit in the bitfield" at the point of the declaration.

https://github.com/llvm/llvm-project/pull/116785


More information about the cfe-commits mailing list