gcc中的C ++ 11样式[[unused]]属性? [英] C++11-style [[unused]] attribute in gcc?
问题描述
在gcc / g ++ 4.9下我可以写:
int x __attribute __((未使用))= f
表示x有意未使用。
是否可以用C ++ 11 [[]]
属性符号来做到这一点?
我试过:
int x [[unused]] = f
但不起作用。
是的,使用<$ c $像已经说过的未使用$ c>
标准允许实现定义的属性太像是 __ attribute __
和 __ declspec
与新语法一起使用。如果编译器不识别属性(在MSVC上编译时的gcc属性作为示例),它将被忽略。 (可能带有警告)
对于gcc,您可以使用gnu前缀和C ++ 11属性语法: [[gnu :: unused ]]
而不是 __属性__((未使用))
同样应该适用于其他gcc属性。
使用gnu前缀的示例
Under gcc/g++ 4.9 I can write:
int x __attribute__((unused)) = f();
to indicate that x is intentionally unused.
Is it possible to do this with the C++11 [[]]
attribute notation somehow?
I tried:
int x [[unused]] = f();
but it doesn't work.
(Yes, I know it is an implementation-defined attribute.)
Yes, use [[gnu::unused]]
Like already said unused
isn't part of the standard attributes specified by the standard.
The standard allows implementation defined attributes too like the __attribute__
and __declspec
ones to be used with the new syntax. If a compiler doesn't recognize an attribute (a gcc attribute when compiling on MSVC as example) it'll simply be ignored. (probably with a warning)
For gcc you can use the gnu prefix and the C++11 attribute syntax: [[gnu::unused]]
instead of __attribute__((unused))
the same should apply for the other gcc attributes too.
这篇关于gcc中的C ++ 11样式[[unused]]属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!