[PATCH] D145642: [clang-format] Annotate lambdas with requires clauses.

Emilia Dreamer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 10 17:36:07 PST 2023


rymiel added a comment.

In D145642#4183539 <https://reviews.llvm.org/D145642#4183539>, @owenpan wrote:

> Would this patch make the end result look worse without "making the requires clause formatting of lambdas
> match the formatting for functions"? If yes, then we should not land it just yet.

Depends on your definition of "worse" :)
I outlined this on the github issue (https://github.com/llvm/llvm-project/issues/61269), essentially:

The result for the example provided on the github issue something like this:

  [&]<typename Callable>(Callable&& callable)
    requires std::is_invocable_v<Callable>
  { static_cast<void>(callable); };

Unlike function declarations, lambdas with a requires clause still have the body on one line. I don't yet know how to go about changing this, and **if** I should at all. This of course isn't an issue if the lambda body has multiple lines.

There is also the case of requires clauses before the parameters, which results in this:

  [&]<typename Callable>
    requires std::is_invocable_v<Callable>
  (Callable &&callable) { static_cast<void>(callable); };

This poses a whole new set of problems (like, starting a line with an opening paren is pretty weird!)
But, this sort of syntax seems fairly obscure: I only found out about it reading the C++ grammar, and the clang frontend itself doesn't actually parse it at all in some cases (I filed https://github.com/llvm/llvm-project/issues/61278 for this)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145642/new/

https://reviews.llvm.org/D145642



More information about the cfe-commits mailing list