[clang-format] Annotate lambdas with requires clauses.
authorEmilia Dreamer <emilia@rymiel.space>
Sun, 26 Mar 2023 01:37:59 +0000 (04:37 +0300)
committerEmilia Dreamer <emilia@rymiel.space>
Sun, 26 Mar 2023 01:38:26 +0000 (04:38 +0300)
commit5409fb38372dbf65a94725ccefab2b993fbb7a9b
treec98f6333b5f6450bf0d49ec10284ca7119117960
parentcd67bbdc2496fbba68c818c6ff82007d89d2bb40
[clang-format] Annotate lambdas with requires clauses.

The C++ grammar allows lambdas to have a *requires-clause* in two
places, either directly after the *template-parameter-list*, such as:

`[] <typename T> requires foo<T> (T t) { ... };`

Or, at the end of the *lambda-declarator* (before the lambda's body):

`[] <typename T> (T t) requires foo<T> { ... };`

Previously, these cases weren't handled at all, resulting in weird
results.

Note that this commit only handles token annotation, so the actual
formatting still ends up suboptimal. This is mostly because I do not yet
know how to approach making the requires clause formatting of lambdas
match the formatting for functions.

Fixes https://github.com/llvm/llvm-project/issues/61269

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D145642
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp