[cfe-dev] unable to traverse FunctionTemplateDecl (right name?) with either RecursiveASTVisitor or Matcher

John P. Feltz jfeltz at gmail.com
Mon Dec 1 13:11:12 PST 2014


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

...
class Vis : public RecursiveASTVisitor<Vis> {
public:
   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().

On 11/29/2014 08:40 PM, James Dennett wrote:
> On Sat, Nov 29, 2014 at 2:48 PM, John P. Feltz <jfeltz at gmail.com 
> <mailto:jfeltz at gmail.com>> wrote:
>
>     Hi,
>
>     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
>     3.5.0
>
>     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.
>
>
> You might try visiting the FunctionDecl and then calling 
> getDescribedFunctionTemplate 
> <https://cs.corp.google.com/#piper///depot/google3/third_party/llvm/llvm/tools/clang/include/clang/AST/Decl.h&ct=xref_jump_to_def&cl=GROK&l=2013&gsn=getDescribedFunctionTemplate> on 
> it to get the associated FunctionTemplateDecl.
>
> -- James
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141201/76cdba7d/attachment.html>


More information about the cfe-dev mailing list