[clang] Properly parse variable template requires clause in lambda
authorEmilia Dreamer <emilia@rymiel.space>
Fri, 17 Mar 2023 08:13:02 +0000 (10:13 +0200)
committerEmilia Dreamer <emilia@rymiel.space>
Fri, 17 Mar 2023 20:29:48 +0000 (22:29 +0200)
commit6acdf58919d5e66809555acf5809b12c54ba79dd
tree058c1da579a704808b68121a2a24139d87a5128d
parent22c1c2d9f9ac0d0c7f4597b0148160b911c9712e
[clang] Properly parse variable template requires clause in lambda

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

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D146140
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaConcept.cpp
clang/test/SemaTemplate/concepts.cpp