Skip to content

Commit cee36b9

Browse files
ojhuntcor3ntin
andcommitted
[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 <[email protected]>
1 parent 76d993b commit cee36b9

File tree

1 file changed

+16
-0
lines changed
  • clang/test/CXX/stmt.stmt/stmt.select/stmt.if

1 file changed

+16
-0
lines changed

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)