User-defined attributes in C++11?

孤者浪人 提交于 2019-12-10 12:55:41

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/34818056/user-defined-attributes-in-c11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!