[clang] [clang] return type not correctly deduced for discarded lambdas (PR #153921)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 15 21:58:32 PDT 2025


ojhunt wrote:

> Yeah this is not correct, simply removing that return statement will cause us to attempt to use a discarded return statement for return type deduction purposes, but that is not supposed to happen.

Ah yeah, I had misunderstood (again) the rules for when otherwise discarded statements have relevant semantics, so I thought this was a case where it would interact with deduction (this is why it's a draft :D)

What is weird to me is that the behavior seems to be producing a `void` type, but given the existence of some _incorrect_ deduction path I can't see where void is coming from: the "obvious" return type of the lambda is a boolean, the undeduced return type is the auto type or other undeduced stand in - so I'd understand an error about a dependent or undeduced return, but the void seems surprising?

For lamdas that have an implicit (rather than deduced, though I would have assumed those were the same from a non-C++ world :D ), there's logic to track the return statements and I think it resolves to void if that list is empty. It seems plausible there's a path that acts similarly for auto returns.



https://github.com/llvm/llvm-project/pull/153921


More information about the cfe-commits mailing list