【发布时间】:2013-11-24 20:58:35
【问题描述】:
This answer 建议 clang 帖子 revision 165082 应该在 AST 中保留所有已解析的属性。
我最初认为这意味着所有属性都将被保留,但事实并非如此:
$ clang++ -v
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
$ cat att.cpp
void f [[noreturn, foo]] () {}
$ clang++ att.cpp -Xclang -ast-dump -fsyntax-only -std=c++11
att.cpp:1:20: warning: unknown attribute 'foo' ignored [-Wattributes]
void f [[noreturn, foo]] () {}
^
att.cpp:1:30: warning: function declared 'noreturn' should not return [-Winvalid-noreturn]
void f [[noreturn, foo]] () {}
^
TranslationUnitDecl 0x102021cd0 <<invalid sloc>>
|-TypedefDecl 0x102022210 <<invalid sloc>> __int128_t '__int128'
|-TypedefDecl 0x102022270 <<invalid sloc>> __uint128_t 'unsigned __int128'
|-TypedefDecl 0x102022630 <<invalid sloc>> __builtin_va_list '__va_list_tag [1]'
`-FunctionDecl 0x1020226d0 <att.cpp:1:1, col:30> f 'void (void)'
|-CompoundStmt 0x1020227b0 <col:29, col:30>
`-CXX11NoReturnAttr 0x102022770 <col:10>
2 warnings generated.
在上面,请注意属性“foo”确实被忽略了,并且在 AST 中不存在,与属性“noreturn”相反。
属性“foo”会在某个时候保留在 AST 中,还是所有属性都必须是实际编译器的一部分(在 Attr.td 等中定义,如 Clang Internals Manual 中所述)保留在AST?
【问题讨论】:
-
据我从 Michael Han 的补丁中可以看出,我希望它们会保留在 AST 中。请注意,没有出现在 AST 转储中并不意味着不存在于 AST 本身;可能只是转储不完整......
标签: c++11 attributes clang