================
@@ -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
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits