Page MenuHomePhabricator

Add function explicit instantiations to owning context
DraftPublic

Authored by davrec on Mar 1 2022, 3:06 PM.
This is a draft revision that has not yet been submitted for review.

Details

Reviewers
None
Summary
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.

Diff Detail

Event Timeline

davrec created this revision.Mar 1 2022, 3:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 3:06 PM
davrec edited the summary of this revision. (Show Details)Mar 1 2022, 3:08 PM
davrec changed the visibility from "Public (No Login Required)" to "davrec (David Rector)".
davrec edited the summary of this revision. (Show Details)Mar 1 2022, 3:22 PM
davrec changed the visibility from "davrec (David Rector)" to "Public (No Login Required)".
davrec changed the visibility from "Public (No Login Required)" to "davrec (David Rector)".Mar 1 2022, 4:03 PM
davrec changed the visibility from "davrec (David Rector)" to "Public (No Login Required)".Mar 1 2022, 5:06 PM
davrec added inline comments.Mar 1 2022, 6:13 PM
clang/include/clang/AST/RecursiveASTVisitor.h
2124

This switch should actually be conditioned on if (!getDerived.shouldVisitTemplateInstantiations()):