Static Assertions inside VarDecl constructor

Hello,

Inside VarDecl constructor (Decl.cpp L1721 in Clang 3.6) there are 2 static assertions as follows;

VarDecl::VarDecl(Kind DK, ASTContext &C, DeclContext *DC,…) {

static_assert(sizeof(VarDeclBitfields) <= sizeof(unsigned),
“VarDeclBitfields too large!”);
static_assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned),
“ParmVarDeclBitfields too large!”);

}

I am trying to add an another field to VarDeclBitfields and it triggers second static assertion in above code.

Could you please explain why sizeof VarDeclBitfields and ParmVarDeclBitfields must be less than sizeof(unsigned) and also what are repercussions if I remove above assertions ?

Thanks
-Thejaka

The purpose of those assertions is to ensure that the bitfields are actually the size we think they are. With MSVC, if you use enum bitfields, things get all messed up, so the assertions were added in r130632.

Hello,

Inside VarDecl constructor (Decl.cpp L1721 in Clang 3.6) there are 2
static assertions as follows;

VarDecl::VarDecl(Kind DK, ASTContext &C, DeclContext *DC,...) {

  static_assert(sizeof(VarDeclBitfields) <= sizeof(unsigned),
          "VarDeclBitfields too large!");
  static_assert(sizeof(ParmVarDeclBitfields) <= sizeof(unsigned),
          "ParmVarDeclBitfields too large!");
  ...
}

I am trying to add an another field to VarDeclBitfields and it triggers
second static assertion in above code.

I made more room in r237648:
http://llvm.org/viewvc/llvm-project?view=revision&revision=237648

Thank you Reid and David.

I will probably use David’s approach in my code (3.6 based) and incorporate new bit fields.

Regards
-Thejaka