Reputation: 3244
Is there a way to create user-defined attributes in C++11 or later?
For example,
[[noreturn]] void exit();
is a compiler-defined C++11 attribute.
I'd like to define something like:
[[comingsoon]] int function(int);
Is there a mechanism for this?
Edit: I should mention I'm using Clang.
Upvotes: 22
Views: 14851
Reputation: 168
For now it's not possible to define user-attributes.
There is, as far as i know, no information about if this feature is planned or not. However, look at this FAQ answer from Stroustrup : https://isocpp.org/wiki/faq/cpp11-language-misc#attributes, especially this part :
One planned use for attributes is improved support for OpenMP. For example:
for [ [ omp::parallel() ] ] (int i=0; i<v.size(); ++i) {
// ...
}
It could mean that they plan to allow programmer to define it's own attribute. Wait & see.
Upvotes: 12
Reputation: 28987
The language provides no way of adding attributes.
Of course, if you are using Clang, you can edit the source of Clang, and add any attributes you like.
Upvotes: 8