C++ 我应该在哪里指定[[gnu::transparent_union]]?

C++ 我应该在哪里指定[[gnu::transparent_union]]?,c++,c++11,clang,C++,C++11,Clang,Clang支持使用。这意味着理论上,我可以使用Clang支持的任何属性,并用[[attribute]]]语法标记它 但是,我在使用transparent\u union属性时遇到了问题。我记得C++让你基本上把属性放在任何地方,所以我尝试了所有这些,但没有效果: [[gnu::transparent_union]] union x { int foo; }; // error: an attribute list cannot appear here union [[gnu::transpar

Clang支持使用。这意味着理论上,我可以使用Clang支持的任何属性,并用
[[attribute]]]
语法标记它

但是,我在使用
transparent\u union
属性时遇到了问题。我记得C++让你基本上把属性放在任何地方,所以我尝试了所有这些,但没有效果:

[[gnu::transparent_union]] union x { int foo; };
// error: an attribute list cannot appear here

union [[gnu::transparent_union]] x { int foo; };
// warning: transparent_union attribute can only be applied to a union definition;
// attribute ignored [-Wignored-attributes]

union x [[gnu::transparent_union]] { int foo; };
// error: an attribute list cannot appear here
// warning: transparent_union attribute can only be applied to a union definition;
// attribute ignored [-Wignored-attributes]

union x { int foo; } [[gnu::transparent_union]];
// error: an attribute list cannot appear here
// warning: transparent_union attribute can only be applied to a union definition;
// attribute ignored [-Wignored-attributes]
使用
\uuuu属性\uuuu
语法的正确位置似乎在联合定义的末尾:

union x { int foo; } __attribute__((transparent_union));
// OK

在C++11标准中,如果有合适的位置,将
[[gnu::transparent_union]]]
放在哪里?

在语法中,它显示属性说明符seq放在类键之后,这就是
union
的含义

class-head: class-key attribute-specifier-seqopt class-head-name class-virt-specifieropt base-clauseopt class-key attribute-specifier-seqopt base-clauseopt [..] class-key: class struct union 似乎是唯一一种不会引发诊断的语法。所以可能是叮当作响的虫子


<>记住<>代码>属性> < /COD>似乎是一段时间:代码> [[Att])/Cuff>是C++的一部分。P> >,<>代码> PuxeluthUngult是C++唯一的属性,在C++上下文中被忽略。
union [[gnu::transparent_union]] x { int foo; };