[PATCH] D23385: Implement __attribute__((require_constant_initialization)) for safe static initialization.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 12 11:28:15 PDT 2016

rsmith added a comment.

Attributes are specified in include/clang/Basic/Attr.td with a (hopefully) fairly self-explanatory declarative syntax. You'll then need to add code to lib/Sema/SemaDeclAttr.cpp to create a corresponding attribute object and attach it to the declaration.

Two implementation approaches seem feasible: either check that the VarDecl has constant initialization at the point when the attribute is attached in SemaDeclAttr.cpp, or attach the attribute without checking and instead perform the check from `Sema::CheckCompleteVariableDeclaration`, around where we currently call `isConstantInitializer` to produce a warning on non-constant initialization -- the effect of the attribute would then be to promote that warning to an error.


More information about the cfe-commits mailing list