[clang] [Clang] Instantiate constexpr function when they are needed. (PR #173537)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 9 01:54:05 PST 2026
================
@@ -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));
+ }
----------------
cor3ntin wrote:
The else case is tooling (ie calling evaluate from tidy or lldb) - I don;t know if a warning make sense in that case
https://github.com/llvm/llvm-project/pull/173537
More information about the cfe-commits
mailing list