template <typename T> T func() { return T(); } template int func<int>();
The second line is not currently represented in AST in its lexical context, though it is among the FunctionTemplateDecl's specializations (with getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition). By contrast, explicit instantiations for classes and variables are represented in their lexical context, in addition to being among their owning TemplateDecl's specializations.
This patch simply adds function explicit instantiations to the lexical context to match the behavior of classes/vars.
Not well tested.
This switch should actually be conditioned on if (!getDerived.shouldVisitTemplateInstantiations()):