Ilya Golovenko
Ilya Golovenko

Reputation: 31

Clang AST for a template method of a template class

I have the following piece of code:

template <typename T>
class Foo
{
  template <typename U>
  void bar() const;
};

[[template <typename T>]]
template <typename U>
void Foo<T>::bar() const
{
}

Dumping the AST tree for method foo gives the following for the method definition (irrelevant details were removed for clarity):

`-FunctionTemplateDecl <line:10:1, line:14:1> col:11:14 bar
 |-TemplateTypeParmDecl <line:10:11, col:20> col:20 typename depth 1 index 0 U
 `-CXXMethodDecl <line:9:1, line:14:1> line:11:14 bar 'void () const'
  `-CompoundStmt <line:12:1, line:14:1>

I cannot figure out how to find location of template <typename T> part (the one which is in [[...]] block). I didn't able to find anything related in clang AST API. Any help will be appreciated.

Upvotes: 2

Views: 775

Answers (1)

Ilya Golovenko
Ilya Golovenko

Reputation: 31

Finally, I found the solution for my own question so posting the answer. Hopefully it maybe helpful for someone else.

It's possible to get location information for outer template parameters using getNumTemplateParameterLists() and getTemplateParameterList() methods of DeclaratorDecl class. See documentation for details.

Upvotes: 1

Related Questions