Since P0857, part of C++20, a *lambda-expression* can contain a
*requires-clause* after its *template-parameter-list*.
While support for this was added as part of
eccc734a69c0c012ae3160887b65a535b35ead3e, one specific case isn't
handled properly, where the *requires-clause* consists of an
instantiation of a boolean variable template. This is due to a
diagnostic check which was written with the assumption that a
*requires-clause* can never be followed by a left parenthesis. This
assumption no longer holds for lambdas.
This diagnostic check would then attempt to perform a "recovery", but it
does so in a valid parse state, resulting in an invalid parse state
instead!
This patch adds a special case when parsing requires clauses of lambda
templates, to skip this diagnostic check.
Fixes https://github.com/llvm/llvm-project/issues/61278
Fixes https://github.com/llvm/llvm-project/issues/61387
Ok, last bit, I promise :) I see that we set up the lambda scope here and push the lambda scope on 1287. Instead of passing a bool, could we just figure out the IsLambdaRequiresClause based on that instead? See definition of PushLambdaScope here: https://clang.llvm.org/doxygen/Sema_8cpp_source.html#l02141
A test to see if that would work would be the one you have below, PLUS an example of a requires clause INSIDE of a lambda that itself isn't a lambda that would reproduce the warning(though I'm not convinced ATM that is possible, I don't think we allow a template inside block scope, unless there is some trick I'm too uncreative enough to come up with). If none exists, just checking the current scope would work and perhaps be more preferential.
We do this rarely, but we do it at least in SemaStmt.cpp in ActOnCapScopeReturnStmt. Just a dyn_cast<LambdaScopeInfo>(getCurFunction()) might be able to replace the bool all over the place.