[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:41 PDT 2026


================
@@ -1776,15 +1777,28 @@ bool CheckBitCast(InterpState &S, CodePtr OpPC, const Type *TargetType,
   return true;
 }
 
-static void compileFunction(InterpState &S, const Function *Func) {
-  const FunctionDecl *Definition;
-  if (!Func->getDecl()->getBody(Definition))
-    return;
-  if (!Definition)
+static void compileFunction(InterpState &S, const Function *Func,
+                            CodePtr OpPC) {
+  const FunctionDecl *Fn = Func->getDecl();
+
+  // [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 (FunctionDefinitionCanBeLazilyInstantiated(Fn) && S.inConstantContext()) {
----------------
cor3ntin wrote:

I made the same comment elsewhere, do we still need S.inConstantContext() ?

https://github.com/llvm/llvm-project/pull/205557


More information about the cfe-commits mailing list