<div dir="ltr"><div><div>I'm trying to write a python tool using libclang (v 3.5.1) as a parser, and I'm running into a problem with the annotation attribute on templated structs.<br><br>With -ast-dump I can see my annotation on both the vanilla structs and the templated structs. Using the bindings/python/clang/cindex.py package however, only vanilla structs have the annotation as a child node, and templated structs seems to be missing it. I don't think it's the python binding itself at fault however, it looks like clang_visitChildren never presents the attribute, but I haven't checked that yet.<br></div><br>If for example testcase.cpp looks like this:<br><br>#define MYATTR __attribute__((annotate("hello")))<br><br>struct MYATTR Foo {<br>};<br><br>template <typename><br>struct MYATTR Bar {<br>};<br><br><br></div>then using a simple python script like <a href="https://github.com/sztomi/code-generator/blob/master/src/dump_ast.py">https://github.com/sztomi/code-generator/blob/master/src/dump_ast.py</a> I get the following output:<br><br><div><div>TRANSLATION_UNIT testcase.cpp<br>  +--STRUCT_DECL Foo<br>  |  +--ANNOTATE_ATTR hello<br>  +--CLASS_TEMPLATE Bar<br>     +--TEMPLATE_TYPE_PARAMETER <br><br></div><div>On the other hand<br></div><div><br>clang -Xclang -ast-dump -fsyntax-only -Wall -Weverything /tmp/testcase.cpp gives:<br><br>TranslationUnitDecl 0x3a5e550 <<invalid sloc>> <invalid sloc><br>|-TypedefDecl 0x3a5ea90 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'<br>|-TypedefDecl 0x3a5eaf0 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'<br>|-TypedefDecl 0x3a5eeb0 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list '__va_list_tag [1]'<br>|-CXXRecordDecl 0x3a5efb0 </tmp/testcase.cpp:3:1, line:4:1> line:3:15 struct Foo definition<br>| |-AnnotateAttr 0x3a5f060 <line:1:31, col:47> "hello"<br>| `-CXXRecordDecl 0x3a5f110 <line:3:1, col:15> col:15 implicit struct Foo<br>`-ClassTemplateDecl 0x3aa2360 <line:6:1, line:8:1> line:7:15 Bar<br>  |-TemplateTypeParmDecl 0x3a5f1a0 <line:6:11> col:11 typename<br>  `-CXXRecordDecl 0x3aa22d0 <line:7:1, line:8:1> line:7:15 struct Bar definition<br>    |-AnnotateAttr 0x3aa25e0 <line:1:31, col:47> "hello"<br>    `-CXXRecordDecl 0x3aa2630 <line:7:1, col:15> col:15 implicit struct Bar<br><br>clang --version<br>clang version 3.5.1 (<a href="https://github.com/llvm-mirror/clang.git">https://github.com/llvm-mirror/clang.git</a> accae81be729aef49eada7c84fd17be68bd049e0) (<a href="https://github.com/llvm-mirror/llvm.git">https://github.com/llvm-mirror/llvm.git</a> 78a5ffc6653a1e72686782a97510eaf14f2ce4ae)<br>Target: x86_64-unknown-linux-gnu<br>Thread model: posix<br><br><br></div><div>I understand from <a href="http://clang.llvm.org/docs/Tooling.html#libclang">http://clang.llvm.org/docs/Tooling.html#libclang</a> the AST provided by libclang isn't as detailed as the full internal AST, but my expectation would be that I'd see the annotation on both structs. I'm not sure if this is a bug in the python binding, libclang, or if I've just missed something. Any ideas?<br></div><div><br></div></div></div>