Skip to content

Commit 16bea73

Browse files
ojhuntcor3ntin
authored andcommitted
[clang] return type not correctly deduced for discarded lambdas (llvm#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 llvm#153884 Fix developed by, and Co-authored-by: Corentin Jabot <[email protected]> (cherry picked from commit bcab8ac)
1 parent fe59f72 commit 16bea73

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5685,7 +5685,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
56855685
};
56865686
Function->setDeclarationNameLoc(NameLocPointsToPattern());
56875687

5688-
EnterExpressionEvaluationContext EvalContext(
5688+
EnterExpressionEvaluationContextForFunction EvalContext(
56895689
*this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
56905690

56915691
Qualifiers ThisTypeQuals;

clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,21 @@ void f2() {
239239

240240
}
241241

242+
namespace GH153884 {
243+
bool f1() {
244+
auto f = [](auto) { return true; };
245+
if constexpr (0)
246+
return f(1);
247+
return false;
248+
}
249+
bool f2() {
250+
auto f = [](auto x) { if (x) return 1.5; else return "wat"; };
251+
// expected-error@-1 {{'auto' in return type deduced as 'const char *' here but deduced as 'double' in earlier return statement}}
252+
if constexpr (0)
253+
return f(1);
254+
// expected-note@-1 {{in instantiation of function template specialization 'GH153884::f2()}}
255+
return false;
256+
}
257+
}
242258

243259
#endif

0 commit comments

Comments
 (0)