[英]Unbalanced parenthesis using __attribute__ in g++
Today I tried clang on a project I have developed some time ago. 今天我尝试了一下我前段时间开发的项目。 I was suprised when it encountered a compilation error, since I had compiled my project successfully using g++. 当遇到编译错误时我感到很惊讶,因为我使用g ++成功编译了我的项目。
This short snippet reproduces the line where the error was encountered: 这个简短的片段再现了遇到错误的行:
int main() {
__attribute__((aligned(16)) char arr[5];
}
Which produces this error: 哪会产生这个错误:
test.cpp:2:32: error: expected ')'
__attribute__((aligned(16)) char arr[5];
^
)
As you can see, there is an umbalanced parenthesis. 如您所见,有一个不平衡的括号。 There are three '(', and two ')'. 有三个'(',和'')'。 This clearly looks like it should actually produce a compilation error. 这显然看起来应该实际产生编译错误。
Is this a valid usage of this keyword? 这是此关键字的有效用法吗? I can't seem to find anything on the documentation that indicates it is. 我似乎无法在文档中找到任何表明它的内容。
I'm using g++ 4.5.2 and clang 2.8. 我正在使用g ++ 4.5.2和clang 2.8。
Note that this error is detected when using gcc instead of g++. 请注意,使用gcc而不是g ++时会检测到此错误。
This would be a compiler bug. 这将是编译器错误。 The compiler sees __attribute__
followed by two opening parentheses, some other tokens and then two closing parentheses, which is probably the “definition” of what an __attribute__
should look like, eg 编译器看到__attribute__
后跟两个开括号,一些其他标记,然后是两个右括号,这可能是__attribute__
应该是什么样的“定义”,例如
<attribute> ::=
__attribute__
'(('
something'))'
<attribute> :: =__attribute__
'(('
something'))'
My guess is that the tokens in between are being interpreted as aligned(16
and by some miracle it still works. 我的猜测是,两者之间的代币被解释为aligned(16
和一些奇迹,它仍然有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.