[PATCH] C11 _Bool bitfield diagnostic
Hubert Tong
hubert.reinterpretcast at gmail.com
Tue Jun 2 06:24:40 PDT 2015
================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:4274-4279
@@ -4273,2 +4273,8 @@
"number of elements must be either one or match the size of the vector">;
+def warn_bitfield_width_longer_than_necessary : Warning<
+ "size of bit-field %0 (%1 bits) exceeds the width needed to represent all "
+ "valid values of that bit-field type">, InGroup<BitFieldWidth>;
+def warn_anon_bitfield_width_longer_than_necessary : Warning<
+ "size of anonymous bit-field (%0 bits) exceeds the width needed to represent "
+ "all valid values of that bit-field type">, InGroup<BitFieldWidth>;
----------------
rsmith wrote:
> rsmith wrote:
> > Since this is a constraint violation according to the C11 standard, this should be an `ExtWarn` or `Extension` rather than merely a `Warning`.
> I think this diagnostic should be more specific. The diagnostic text should make it clear that: (1) the problem is that the field has a boolean type, and (2) why that might deserve a warning. Something like "ISO C11 forbids bit-field of type %0 of size greater than 1 (%1 specified)", maybe.
I have not found any normative text which indicates that _Bool cannot have width greater then 1. Also, the proposed new message text makes it less clear that the property is platform-dependent.
Note that the check associated with _Bool hard-codes "1", and the message may be emitted even when the constraint is not violated. The message text proposed in the patch is sufficiently generic to accommodate that.
================
Comment at: lib/Sema/SemaDecl.cpp:12341
@@ +12340,3 @@
+ // different platforms
+ if (getLangOpts().C11 &&
+ FieldTy->isBooleanType() &&
----------------
rsmith wrote:
> It looks like this should apply in all modes that aren't C++: even in C99, we have a constraint in 6.7.2.1 that the specified bit-width cannot be greater than the width of the type, and width is defined in 6.2.6.2 as the number of precision + sign bits.
Yes, this was a change applied in TC2.
http://reviews.llvm.org/D10018
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list