[clang] [Clang] Instantiate constexpr function when they are needed. (PR #173537)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 25 11:49:25 PST 2025
================
@@ -1526,13 +1527,30 @@ bool CheckFunctionDecl(InterpState &S, CodePtr OpPC, const FunctionDecl *FD) {
return diagnoseCallableDecl(S, OpPC, FD);
}
-static void compileFunction(InterpState &S, const Function *Func) {
- const FunctionDecl *Definition = Func->getDecl()->getDefinition();
- if (!Definition)
+static void compileFunction(InterpState &S, const Function *Func,
+ SourceLocation Loc) {
+
+ 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 (!Fn->isDefined() && Fn->isImplicitlyInstantiable() && Fn->isConstexpr() &&
+ S.inConstantContext() && !S.TryConstantInitialization &&
+ !S.checkingPotentialConstantExpression()) {
----------------
Sirraide wrote:
Can you move this entire condition into a helper function somewhere (maybe make it a member of `State`)?
https://github.com/llvm/llvm-project/pull/173537
More information about the cfe-commits
mailing list