https://github.com/ojhunt updated https://github.com/llvm/llvm-project/pull/153921
>From cee36b9d023f97b55bf01220ccd6f404311db339 Mon Sep 17 00:00:00 2001 From: Oliver Hunt <oli...@apple.com> Date: Fri, 15 Aug 2025 21:04:07 -0700 Subject: [PATCH 1/2] [clang] return type not correctly deduced for discarded lambdas The early return for lamda expressions with deduced return types in Sema::ActOnCapScopeReturnStmt meant that we were not actually perform the required return type deduction for such lambdas when in a discarded context. This PR removes that early return allowing the existing return type deduction steps to be performed. Fixes #GH153884 Fix developed by and Co-authored-by: Corentin Jabot <corentinja...@gmail.com> --- .../CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp index abb42447d3e0b..05830de9891fe 100644 --- a/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp +++ b/clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp @@ -239,5 +239,21 @@ void f2() { } +namespace GH153884 { + bool f1() { + auto f = [](auto) { return true; }; + if constexpr (0) + return f(1); + return false; + } + bool f2() { + auto f = [](auto x) { if (x) return 1.5; else return "wat"; }; + // expected-error@-1 {{'auto' in return type deduced as 'const char *' here but deduced as 'double' in earlier return statement}} + if constexpr (0) + return f(1); + // expected-note@-1 {{in instantiation of function template specialization 'GH153884::f2()}} + return false; + } +} #endif >From 1d4875dcc2a5ac673492cc80768e82f17b39fc19 Mon Sep 17 00:00:00 2001 From: Oliver Hunt <oli...@apple.com> Date: Sun, 17 Aug 2025 16:12:28 -0700 Subject: [PATCH 2/2] Make the correct fix --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index f02a295220efb..6b423ce06523a 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -5669,7 +5669,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, }; Function->setDeclarationNameLoc(NameLocPointsToPattern()); - EnterExpressionEvaluationContext EvalContext( + EnterExpressionEvaluationContextForFunction EvalContext( *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); Qualifiers ThisTypeQuals; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits