简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM