Explicit Template Arguments in DeclRefExpressions


I’m trying to translate Template arguments (as part of a source to source translation tool). Therefore I need only to consider explicit arguments (as written in the source)

However the TemplateArgument I receive always have random kind numbers (when static casting to int and print them) therefore I never get the kind of the argument and can’t translate the arguments.

My code looks as follows

  unsigned templateArgs = declRefExpr->getNumTemplateArgs();
  auto astTemplateArgsList = declRefExpr->getExplicitTemplateArgs();
  for(unsigned i = 0; i < templateArgs; i++)


Does anyone see what is wrong with this code or where could be the error?

Furthermore I looked into the implementation of getTemplateArgs() (which is called by the [] operator) http://clang.llvm.org/doxygen/TemplateBase_8h_source.html#l00561 there it is just return “this+1” with a cast which is quite un-intuitive but I guess it is correct?

Thanks for any help.


Hm solved this myself by replacing


which is weird considering the implementation of operator[] does the same?