Skip to content

[clang-format] Continuation indent of requires-expression should be configurable #56283

@Vigilans

Description

@Vigilans

In clang-13, a concept definition with requires-expression will be formatted like this:

template <typename EnvT>
concept Env = requires(EnvT&& env) {
    { step(env) } -> std::convertible_to<int>;
};

But after commits in https://reviews.llvm.org/D113319, above code will be formatted to:

template <typename EnvT>
concept Env = requires (EnvT&& env) {
                  { step(env) } -> std::convertible_to<int>;
              };

After some investigation, it reveals that the difference was rooted in following code:

if (Current.is(TT_RequiresExpression))
CurrentState.NestedBlockIndent = State.Column;

It unconditionally sets the indentation to be aligned with requires keyword. After removing it and recompile clang-format, the code is formatted as what clang-13 does:

template <typename EnvT>
concept Env = requires (EnvT&& env) {
    { step(env) } -> std::convertible_to<int>;
};

These two indentations are just different style preferences, therefore should be made configurable in .clang-format file.

@HazardyKnusperkeks

Metadata

Metadata

Assignees

Labels

clang-formatenhancementImproving things as opposed to bug fixing, e.g. new or missing featuregood first issuehttps://github.com/llvm/llvm-project/contribute

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions