diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 969856a8f978c4..615e8879ac4744 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -1017,7 +1017,6 @@ Bug Fixes to C++ Support (#GH88081), (#GH89496), (#GH90669), (#GH91633) and (#GH97453). - Fixed a crash in constraint instantiation under nested lambdas with dependent parameters. - Fixed handling of brace ellison when building deduction guides. (#GH64625), (#GH83368). -- Clang now instantiates local constexpr functions eagerly for constant evaluators. (#GH35052), (#GH94849) - Fixed a failed assertion when attempting to convert an integer representing the difference between the addresses of two labels (a GNU extension) to a pointer within a constant expression. (#GH95366). - Fix immediate escalation bugs in the presence of dependent call arguments. (#GH94935) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index d6b85cbcaf56b5..b0f953ea0a13a2 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -17958,17 +17958,16 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, if (FirstInstantiation || TSK != TSK_ImplicitInstantiation || Func->isConstexpr()) { - if (Func->isConstexpr()) + if (isa(Func->getDeclContext()) && + cast(Func->getDeclContext())->isLocalClass() && + CodeSynthesisContexts.size()) + PendingLocalImplicitInstantiations.push_back( + std::make_pair(Func, PointOfInstantiation)); + else if (Func->isConstexpr()) // Do not defer instantiations of constexpr functions, to avoid the // expression evaluator needing to call back into Sema if it sees a // call to such a function. InstantiateFunctionDefinition(PointOfInstantiation, Func); - else if (isa(Func->getDeclContext()) && - cast(Func->getDeclContext()) - ->isLocalClass() && - CodeSynthesisContexts.size()) - PendingLocalImplicitInstantiations.push_back( - std::make_pair(Func, PointOfInstantiation)); else { Func->setInstantiationIsPending(true); PendingInstantiations.push_back( diff --git a/clang/test/SemaTemplate/instantiate-local-class.cpp b/clang/test/SemaTemplate/instantiate-local-class.cpp index 7eee131e28d60c..298233739900f6 100644 --- a/clang/test/SemaTemplate/instantiate-local-class.cpp +++ b/clang/test/SemaTemplate/instantiate-local-class.cpp @@ -512,24 +512,26 @@ namespace LambdaInDefaultMemberInitializer { } #if __cplusplus >= 201703L -namespace GH35052 { -template constexpr int func(F f) { - if constexpr (f(1UL)) { - return 1; +// Reduced from https://github.com/llvm/llvm-project/issues/98526 +// This relies on the deferral instantiation of the local lambda, otherwise we would fail in DeduceReturnType(). +namespace local_recursive_lambda { + +template struct recursive_lambda { + template auto operator()(Args &&...args) const { + return fn(*this, args...); } - return 0; -} + F fn; +}; -int main() { - auto predicate = [](auto v) /*implicit constexpr*/ -> bool { - return v == 1; - }; +template recursive_lambda(F) -> recursive_lambda; - static_assert(predicate(1)); - return func(predicate); +void foo() { + recursive_lambda{[&](auto &self_fn, int) -> int { + return self_fn(0); + }}(0); } -} // namespace GH35052 +} // namespace local_recursive_lambda #endif