HandleTranslationUnit and Function Templates

Hi,

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)?

Thanks,
Nilesh.

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:
https://github.com/include-what-you-use/include-what-you-use/blob/master/iwyu.cc#L3454
https://github.com/include-what-you-use/include-what-you-use/blob/master/iwyu_ast_util.cc#L649

called from here:
https://github.com/include-what-you-use/include-what-you-use/blob/master/iwyu.cc#L3427

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

- Kim