]> granicus.if.org Git - clang/commitdiff
[Sema] Don't allow unverified bitfields in FieldDecls
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 26 Apr 2015 04:58:18 +0000 (04:58 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 26 Apr 2015 04:58:18 +0000 (04:58 +0000)
VerifyBitField must be called if we are to form a bitfield FieldDecl.
We will not verify the bitfield if the decl is known to be malformed in
other ways; pretend that we don't have a bitfield if this happens.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235816 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/bitfield.c

index 339280614ff9a68f6d992f2164b443ba81de8948..07dbdaf9968ffd13d5a4de515eedf304d53597c5 100644 (file)
@@ -12481,8 +12481,10 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
     InvalidDecl = true;
 
   bool ZeroWidth = false;
+  if (InvalidDecl)
+    BitWidth = nullptr;
   // If this is declared as a bit-field, check the bit-field.
-  if (!InvalidDecl && BitWidth) {
+  if (BitWidth) {
     BitWidth = VerifyBitField(Loc, II, T, Record->isMsStruct(Context), BitWidth,
                               &ZeroWidth).get();
     if (!BitWidth) {
index fb72213475aef5273f3b5e5800642c782ced6109..f214b671f6f96d8c34deffd1b2c0a5d070104150 100644 (file)
@@ -74,3 +74,7 @@ typedef __typeof__(+(--t5.n)) Signed; // This should not promote to signed.
 
 typedef __typeof__(+(t5.n++)) Unsigned; // Post-increment is underspecified, but seems to
 typedef __typeof__(+(t5.n--)) Unsigned; // also act like compound-assignment.
+
+struct Test6 {
+  : 0.0; // expected-error{{type name requires a specifier or qualifier}}
+};