[clang] [Clang] Instantiate functions from constant evaluation. (PR #205557)

Daniel M. Katz via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 26 08:51:43 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()) {
----------------
katzdm wrote:

As per discussion elsewhere on the PR, I think we want to keep this for now.

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


More information about the cfe-commits mailing list