[cfe-dev] HandleTranslationUnit and Function Templates

Kim Gräsman via cfe-dev cfe-dev at lists.llvm.org
Thu Oct 8 22:18:21 PDT 2015


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

On Thu, Oct 8, 2015 at 7:47 PM, Nilesh Mahajan via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> 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.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list