HandleTranslationUnit and Function Templates


I am writing a tool that overrides HandleTranslationUnit in my
ASTConsumer. My aim is to examine function calls and find locations of
corresponding function declarations. It seems that this does not work
for function templates. I am guessing this has to do with two-phase
lookup? Is there a way around this or I have to override
HandleTopLevelDecl (which works)?


Hi Nilesh,

Are you using -fdelayed-template-parsing (either directly or
indirectly via -fms-compatibility or -fms-extensions)?

If so, function templates are late-parsed and don't exist yet when AST
visitation runs.

We ran into this in IWYU, and worked around it by explicitly parsing
function templates, see here:

called from here:

If you do this *before* traversing the translation unit decl, the
templates will be picked up as expected.

- Kim