[clang] [clang] Add clang::preferred_type attribute for bitfields (PR #69104)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 19 07:23:52 PDT 2023


erichkeane wrote:

>I meant warning on something like https://godbolt.org/z/Ma17xjjc5. That doesn't seem like it should be that hard.

Yeah, that one wouldn't be too hard (and isn't a pattern I've ever seen TBH), but doesn't solve the problem at hand, which is that it is very common to need to use the same type for multiple enum values in bitfields, so folks use unsigned, thus the type name is lost.  

>@erichkeane I guess you'd be pretty happy if our enums were declared the following way:

Not really?  That doesn't gain us the 'we must change where this is stored' situation like a `preferred_type` attribute would/could.  We MIGHT be able to get away with a comment on top of that with a list of places that needs to ALSO be changed, but we end up missing similar comments today anyway.  

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


More information about the cfe-commits mailing list