This compiles when using clang -std=gnu++11 -c test.cpp
:
void test() {
[[random text here]]
if (0) {
}
}
But this gives error main.cpp:3:1: error: expected statement
:
void test() {
[[random text here]]
}
If I compile with clang -std=gnu++11 -S -emit-llvm main.cpp
and look at the LLVM code it looks like the [[...]]
line has no effect:
define void @_Z5testv() nounwind uwtable ssp {
ret void
}
Any ideas why? bug or some C++11 syntax or GNU extension syntax?
Im using clang from Xcode 4.4.1 (Apple clang version 4.0 (tags/Apple/clang-421.0.60) (based on LLVM 3.1svn).
This is using C++11's attribute syntax. "random text here
" is therefore assumed to be an attribute. By the C++11 specification, an attribute can modify many statements and declarations.
Attributes can be statements, but they have to actually be statements. Meaning they end in a ;
just like many other C++ statements.
The set of attributes supported by an implementation is implementation-defined (and Clang doesn't support any. Indeed, it apparently isn't supposed to support attribute syntax at all, according to the website). Attributes not implemented by a particular implementation should be ignored, which is why it has no effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With