How to make clang-format not add new line before opening brace of a function with requires clause?

65 Views Asked by At

When I auto-format with Clang-format, it is always inserting a newline before brace when requires clause is there.

This

constexpr auto size() const noexcept
  requires(!Unique) {
    return stdr::fold_left(views | stdv::transform(stdr::size), 0, std::plus<int>{});
}

is becoming this

constexpr auto size() const noexcept
  requires(!Unique)
{
    return stdr::fold_left(views | stdv::transform(stdr::size), 0, std::plus<int>{});
}

How to avoid it?

I have tried

RequiresClausePosition: WithPreceding
BraceWrapping:
  AfterClass:      false
  AfterControlStatement: false
  AfterEnum:       false
  AfterFunction:   false
  AfterNamespace:  false
  AfterObjCDeclaration: false
  AfterStruct:     false
  AfterUnion:      false
  BeforeCatch:     false
  BeforeElse:      false
  IndentBraces:    false
BreakBeforeBraces: Custom

but these are not working.

1

There are 1 best solutions below

1
Ted Lyngmo On BEST ANSWER

It looks like you want RequiresClausePosition: SingleLine:

RequiresClausePosition: SingleLine

Try to put everything in the same line if possible. Otherwise normal line breaking rules take over.

Example with ColumnLimit: 80:

constexpr auto size() const noexcept requires(!Unique) {
    return stdr::fold_left(views | stdv::transform(stdr::size), 0,
                           std::plus<int>{});
}