[PATCH] D129443: [clang-format] Add option for aligning requires clause body

Zhi-Hao Ye via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 12 09:59:20 PDT 2022


Vigilans added a comment.

In my knowledge of clang-format, `Requires Clause` and `Requires Expression` are treated differently. 
In cppreference <https://en.cppreference.com/w/cpp/language/constraints>, A `Requires Clause` is specific to the `requires` keyword used for constraints on template arguments or on a function declaration. In this issue's context of continuation indent, the `requires` keyword is used for `Requires Expression`, just as the code relative to this diff suggests:

  if (Current.is(TT_RequiresExpression) /* <-- it's requires expression here */ && Style.AlignRequiresClauseBody)
    CurrentState.NestedBlockIndent = State.Column;

Some more example options in clang-format:

- `IndentRequiresClause`

  true:
  template <typename It>
    requires Iterator<It>
  void sort(It begin, It end) {
    //....
  }
  
  false:
  template <typename It>
  requires Iterator<It>
  void sort(It begin, It end) {
    //....
  }

- `SpaceBeforeParensOptions -> AfterRequiresInClause`

  true:                                  false:
  template<typename T>            vs.    template<typename T>
  requires (A<T> && B<T>)                requires(A<T> && B<T>)
  ...                                    ...

- `SpaceBeforeParensOptions -> AfterRequiresInExpression`

  true:                                  false:
  template<typename T>            vs.    template<typename T>
  concept C = requires (T t) {           concept C = requires(T t) {
                ...                                    ...
              }                                      }

So the option in this diff should use `RequiresExpressionBody`.

Besides, there is an option that does similar thing as this diff do:

- `LambdaBodyIndentation`

> The indentation style of lambda bodies. Signature (the default) causes the lambda body to be indented one additional level relative to the indentation level of the signature. OuterScope forces the lambda body to be indented one additional level relative to the parent scope containing the lambda signature. For callback-heavy code, it may improve readability to have the signature indented two levels and to use OuterScope. The KJ style guide requires OuterScope. KJ style guide
>
> Possible values:
>
> - LBI_Signature (in configuration: Signature) Align lambda body relative to the lambda signature. This is the default.
>
>   someMethod(
>       [](SomeReallyLongLambdaSignatureArgument foo) {
>         return;
>       });
>
> - LBI_OuterScope (in configuration: OuterScope) Align lambda body relative to the indentation level of the outer scope the lambda signature resides in.
>
>   someMethod(
>       [](SomeReallyLongLambdaSignatureArgument foo) {
>     return;
>   });

So we may select a similar option naming and values as this option?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129443



More information about the cfe-commits mailing list