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

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 12 09:30:38 PDT 2016


majnemer added inline comments.

================
Comment at: lib/Sema/SemaDecl.cpp:10388-10390
@@ -10387,2 +10387,5 @@
 
+  // Cache the result of checking for constant initialization.
+  Optional<bool> HasConstInit;
+
   if (var->getTLSKind() == VarDecl::TLS_Static) {
----------------
You could use a lambda to abstract away the "check if it's cached, if not query" logic.

================
Comment at: lib/Sema/SemaDecl.cpp:10485
@@ +10484,3 @@
+  if (var->hasAttr<RequireConstantInitAttr>() && !Init)
+     Diag(var->getLocation(), diag::err_require_constant_init_failed);
+
----------------
Any reason not to use the already existing `err_init_element_not_constant`?


https://reviews.llvm.org/D23385





More information about the cfe-commits mailing list