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

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 30 14:50:28 PDT 2016


EricWF marked 3 inline comments as done.

================
Comment at: include/clang/Basic/AttrDocs.td:836
@@ +835,3 @@
+  let Content = [{
+This attribute specifies that the variable to which it is attached is intended
+to have a `constant initializer <http://en.cppreference.com/w/cpp/language/constant_initialization>`_
----------------
aaron.ballman wrote:
> I don't think I ever heard whether this attribute was usable in C or not. I suspect it's not particularly needed in C. If that's true, we should state that in the documentation, and consider making the attribute a C++-only attribute?
I think it would be somewhat useful in C.  In particular if you have globals initialized from values you don't own. Example:

```
#include <y.h>
ATTR int x = y; // Will diagnose if  becomes 'y' is a non-constant expression.
```

However the current implementation only handles C++ and I'm satisfied with that. I'll mark the attribute as C++ only and document that change.


https://reviews.llvm.org/D23385





More information about the cfe-commits mailing list