Access default template parameters using libclang in python (or C)


I am trying to do some C++ introspection using the AST generated by
libclang. I use the python bindings, but they seem to be a pretty
straightforward mapping to the C API.

There seems to be no way to access the default argument to template
parameters, like

template<class S, class T = bar<S> > struct foo {};

No AST node is generated for bar<S> and there is no method for access
the default argument. Using clangs internal API this is possible.

Is there any way to use libclang for this?


The thread linked below says it is necessary to use the tokenizer to get the value for default function arguments.
A similar solution may work for template args.

Here is an approach to find function arguments using the Julia libclang bindings - I think the Python tokenizer API is similar:

And, just in case you haven’t seen it, there is a fantastic blog post about Python+libclang and C++: