unable to traverse FunctionTemplateDecl (right name?) with either RecursiveASTVisitor or Matcher


I can't seem to traverse the following with either a RecursiveASTVisitor or a AST Matcher converted to an ASTConsumer:

template<typename T> void h(T x) { .. }

First some things I'd like to note:
1) $ llvm-config --version

2) 'clang' actually does find the template function, so I suspect I'm doing something wrong in either the visitor and matcher, or in the compiler setup:
$ clang -Xclang -ast-dump -fsyntax-only file.cc
FunctionTemplateDecl 0x23e5330 <line:13:1, line:15:1> line:13:27 h

3) I am not a C++ expert, and I am a libtooling newbie.

I've attached the parsed subject (file.cc) and the code I'm using to build and run the test-case.

Thanks in advance,
John Feltz

file.cc (264 Bytes)

Makefile (2.52 KB)

clang_testcase.cc (4.62 KB)

You might try visiting the FunctionDecl and then calling
it to get the associated FunctionTemplateDecl.

-- James

Did you look at my failing test-case that I attached earlier? Specifically:

class Vis : public RecursiveASTVisitor {
Vis(SourceManager& sm_) : sm(sm_) {}

bool VisitFunctionTemplateDecl(FunctionTemplateDecl *tf) {
std::cout << “visiting template func decl” << std::endl;
return true;
bool VisitFunctionDecl(FunctionDecl *f) {
std::cout << "visiting func decl: " << f->getNameInfo().getAsString() << std::endl;
return true;

SourceManager& sm;

Neither functions find h().

What happens if you add a call to template function inside main?


No change:

visiting func decl: f
visiting func decl: g
visiting func decl: main

Also with:

file.cc:1:10: fatal error: ‘iostream’ file not found
visiting func decl: f
visiting func decl: g
visiting func decl: main

also h() shows up for #include <iostream_adsf> in both:
$ clang-query file.cc –
clang-query> m functionTemplateDecl()

$ clang -Xclang -ast-dump -fsyntax-only file.cc