[cfe-dev] Static Assertions inside VarDecl constructor

Reid Kleckner rnk at google.com
Thu Jun 4 17:11:49 PDT 2015


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.

On Tue, Jun 2, 2015 at 9:24 AM, Amila Jayasekara <thejaka.amila at gmail.com>
wrote:

> 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
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150604/615064c3/attachment.html>


More information about the cfe-dev mailing list