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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 11:01:25 PDT 2023


================
@@ -3153,6 +3153,12 @@ def err_invalid_branch_protection_spec : Error<
   "invalid or misplaced branch protection specification '%0'">;
 def warn_unsupported_branch_protection_spec : Warning<
   "unsupported branch protection specification '%0'">, InGroup<BranchProtection>;
+def warn_attribute_underlying_type_mismatch : Warning<
+  "underlying type %0 of enumeration %1 doesn't match bit-field type %2">,
+  InGroup<BitFieldType>;
+def warn_attribute_bool_bitfield_width : Warning<
+  "bit-field that holds a boolean value should have width of 1 instead of %0">,
----------------
AaronBallman wrote:

Thinking out loud: do we want to diagnose this situation at all? It leaves me wondering why we wouldn't also issue `bit-field that holds a 'short' should have a width of 16 instead of N`, etc. On the one hand, bool is a bit special given that it's a 1-bit type. But on the other hand: 1) what's the harm in this pattern, 2) how does a user silence this diagnostic in the case then intentionally want a 2-bit bool aside from disabling the diagnostic entirely?

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


More information about the cfe-commits mailing list