1

In the following c++ source file:

1 //file my_func.cpp
2 void template<typename Bar> foo(Bar& bar) {
3     // some code
4 }
5 template void foo<double>(double&);

I want to get the beginning and the end of the explicit instantiation of the function template foo in form of a clang::SourceLocation.

I have tried:

clang::FunctionDecl* FS; //the AST node for the foo<double> function obtained by some AST matcher
if(const clang::FunctionTemplateSpecializationInfo* TSI = FS->getTemplateSpecializationInfo()) {
    clang::SourceLocation = TSI->getPointOfInstantiation();
}

This location will be line 5 and column 15 (the begin of "foo"). I have not found a way to obtain the begin of the complete explicit instantiation and the end. Is there a way to achieve this?

mpeschke
  • 308
  • 3
  • 11
  • I would like to know the same. In my case, `FS->isTemplateInstantiation()` returns `false` and `getTemplateSpecializationInfo` returns `nullptr` – DoDo Aug 18 '22 at 10:22
  • I asked the same in the clang discord. It seems that this information cannot be queried. One has to add this already in the clang-sema library to store the relevant information in the AST. – mpeschke Aug 22 '22 at 08:58

0 Answers0