[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:38:17 PDT 2016
rsmith added a comment.
Sorry about the redundant previous comment, the thread got forked by the change of subject and I missed the updated patch.
================
Comment at: lib/Sema/SemaDecl.cpp:10484-10485
@@ -10478,1 +10483,4 @@
+ if (var->hasAttr<RequireConstantInitAttr>() && !Init)
+ Diag(var->getLocation(), diag::err_require_constant_init_failed);
+
----------------
I think this check is incorrect: we perform constant initialization (to zero) for globals with no initializer.
================
Comment at: lib/Sema/SemaDecl.cpp:10500
@@ +10499,3 @@
+ if (!*HasConstInit)
+ Diag(var->getLocation(), diag::warn_global_constructor)
+ << Init->getSourceRange();
----------------
Instead of diagnosing the condition separately (and getting both a warning and an error for the same situation), it would seem preferable to change this to produce either `diag::warn_global_constructor` or your new error depending on whether the attribute is present. This would also remove the duplicate error messages if the attribute is specified on an object that is also marked `constexpr`.
https://reviews.llvm.org/D23385
More information about the cfe-commits
mailing list