[llvm-branch-commits] [clang] 16bea73 - [clang] return type not correctly deduced for discarded lambdas (#153921)
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Aug 20 23:06:27 PDT 2025
Author: Oliver Hunt
Date: 2025-08-21T08:06:21+02:00
New Revision: 16bea73be5aeab1cac87a7f73d84d63a8ec438a7
URL: https://github.com/llvm/llvm-project/commit/16bea73be5aeab1cac87a7f73d84d63a8ec438a7
DIFF: https://github.com/llvm/llvm-project/commit/16bea73be5aeab1cac87a7f73d84d63a8ec438a7.diff
LOG: [clang] return type not correctly deduced for discarded lambdas (#153921)
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 #153884
Fix developed by, and
Co-authored-by: Corentin Jabot <corentinjabot at gmail.com>
(cherry picked from commit bcab8ac126c0b4c439caa3104d66d33d0f70f86f)
Added:
Modified:
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index e2c3cdcd536bc..d2b87f2702a9c 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5685,7 +5685,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
};
Function->setDeclarationNameLoc(NameLocPointsToPattern());
- EnterExpressionEvaluationContext EvalContext(
+ EnterExpressionEvaluationContextForFunction EvalContext(
*this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
Qualifiers ThisTypeQuals;
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 at -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 at -1 {{in instantiation of function template specialization 'GH153884::f2()}}
+ return false;
+ }
+}
#endif
More information about the llvm-branch-commits
mailing list