[英]Why does this C++ code compile when using clang -std=gnu++11?
这在使用clang -std=gnu++11 -c test.cpp
:
void test() {
[[random text here]]
if (0) {
}
}
但是这给出了错误main.cpp:3:1: error: expected statement
:
void test() {
[[random text here]]
}
如果我使用clang -std=gnu++11 -S -emit-llvm main.cpp
编译并查看LLVM代码,它看起来像[[...]]
行无效:
define void @_Z5testv() nounwind uwtable ssp {
ret void
}
有什么想法吗? 错误或一些C ++ 11语法或GNU扩展语法?
我使用Xcode 4.4.1中的clang(Apple clang 4.0版(标签/ Apple / clang-421.0.60)(基于LLVM 3.1svn)。
这是使用C ++ 11的属性语法。 因此,“ random text here
”被假定为属性。 通过C ++ 11规范,属性可以修改许多语句和声明。
属性可以是语句,但它们实际上必须是语句 。 意思是他们以一个;
就像许多其他C ++语句一样。
实现支持的属性集是实现定义的(并且Clang不支持任何属性。实际上, 根据网站 ,显然根本不应该支持属性语法)。 应忽略特定实现未实现的属性,这就是它无效的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.