[clang] [Clang] Instantiate functions from constant evaluation. (PR #205557)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 24 07:18:42 PDT 2026
================
@@ -6997,6 +6999,30 @@ static bool handleTrivialCopy(EvalInfo &Info, const ParmVarDecl *Param,
CopyObjectRepresentation);
}
+bool FunctionDefinitionCanBeLazilyInstantiated(const FunctionDecl *FD) {
+ if (FD->isDefined() || !FD->isImplicitlyInstantiable() || !FD->isConstexpr())
+ return false;
+
+ FunctionDecl *Pattern = FD->getTemplateInstantiationPattern();
+ return Pattern && Pattern->isDefined();
+}
+
+static void TryInstantiateFunctionBeforeCall(const FunctionDecl *FD,
+ EvalInfo &Info,
+ SourceLocation Loc) {
+
+ // [C++26] [temp.inst] p5
+ // [...] the function template specialization is implicitly instantiated
+ // when the specialization is referenced in a context that requires a function
+ // definition to exist or if the existence of the definition affects the
+ // semantics of the program.
+
+ SemaProxy *SP = Info.getSemaProxy();
+ if (SP && FunctionDefinitionCanBeLazilyInstantiated(FD) &&
+ Info.InConstantContext)
+ SP->instantiateFunctionDefinition(Loc, const_cast<FunctionDecl *>(FD));
+}
+
----------------
cor3ntin wrote:
So, in your approach, do we still need `Info.InConstantContext` or is that true by construction and it should be an assert?
https://github.com/llvm/llvm-project/pull/205557
More information about the cfe-commits
mailing list