Inconsistent reporting of annotation attributes in libclang?

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.

With -ast-dump I can see my annotation on both the vanilla structs and the templated structs. Using the bindings/python/clang/ 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.

If for example testcase.cpp looks like this:

#define MYATTR attribute((annotate(“hello”)))

struct MYATTR Foo {

struct MYATTR Bar {

then using a simple python script like I get the following output:



On the other hand

clang -Xclang -ast-dump -fsyntax-only -Wall -Weverything /tmp/testcase.cpp gives:

TranslationUnitDecl 0x3a5e550 <>

-TypedefDecl 0x3a5ea90 <> implicit __int128_t ‘__int128’
-TypedefDecl 0x3a5eaf0 <> implicit __uint128_t ‘unsigned __int128’
-TypedefDecl 0x3a5eeb0 <> implicit __builtin_va_list ‘__va_list_tag [1]’
-CXXRecordDecl 0x3a5efb0 </tmp/testcase.cpp:3:1, line:4:1> line:3:15 struct Foo definition

-AnnotateAttr 0x3a5f060 <line:1:31, col:47> “hello”
-CXXRecordDecl 0x3a5f110 <line:3:1, col:15> col:15 implicit struct Foo -ClassTemplateDecl 0x3aa2360 <line:6:1, line:8:1> line:7:15 Bar
-TemplateTypeParmDecl 0x3a5f1a0 line:6:11 col:11 typename
-CXXRecordDecl 0x3aa22d0 <line:7:1, line:8:1> line:7:15 struct Bar definition -AnnotateAttr 0x3aa25e0 <line:1:31, col:47> "hello" -CXXRecordDecl 0x3aa2630 <line:7:1, col:15> col:15 implicit struct Bar

clang --version
clang version 3.5.1 ( accae81be729aef49eada7c84fd17be68bd049e0) ( 78a5ffc6653a1e72686782a97510eaf14f2ce4ae)
Target: x86_64-unknown-linux-gnu
Thread model: posix

I understand from 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?