Skip to content

Commit eca8134

Browse files
committed
[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
1 parent 76d993b commit eca8134

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

clang/lib/Sema/SemaStmt.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,8 +3533,6 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation ReturnLoc,
35333533
return StmtError();
35343534
RetValExp = ER.get();
35353535
}
3536-
return ReturnStmt::Create(Context, ReturnLoc, RetValExp,
3537-
/* NRVOCandidate=*/nullptr);
35383536
}
35393537

35403538
if (HasDeducedReturnType) {

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)