================
@@ -7064,6 +7066,28 @@ static bool handleTrivialCopy(EvalInfo &Info, const 
ParmVarDecl *Param,
       CopyObjectRepresentation);
 }
 
+static void InstantiateFunctionBeforeCall(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.
+
+  if (!FD->isDefined() && FD->isImplicitlyInstantiable() && FD->isConstexpr() 
&&
+      Info.InConstantContext && !Info.TryConstantInitialization &&
+      !Info.checkingPotentialConstantExpression()) {
+
+    SemaProxy *SP = Info.getASTContext().getSemaProxy();
+    // Try to instantiate the definition if Sema is available
+    // (i.e during the initial parse of the TU).
+    if (SP) {
+      SP->InstantiateFunctionDefinition(Loc, const_cast<FunctionDecl *>(FD));
+    }
----------------
zyn0217 wrote:

I wonder if we should have a warning for the else branch, so that users know 
the behavior might be wrong (generally a missed instantiation should be our bug)

https://github.com/llvm/llvm-project/pull/173537
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to