Skip to content

Commit bcab8ac

Browse files
ojhuntcor3ntin
andauthored
[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 <[email protected]>
1 parent 16aa283 commit bcab8ac

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
@@ -5669,7 +5669,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
56695669
};
56705670
Function->setDeclarationNameLoc(NameLocPointsToPattern());
56715671

5672-
EnterExpressionEvaluationContext EvalContext(
5672+
EnterExpressionEvaluationContextForFunction EvalContext(
56735673
*this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
56745674

56755675
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)