Skip to content

[clang-format] AlignAfterOpenBracket: BlockIndent: weird close-bracket when ')' or qualifiers exceeds ColumnLimit #55473

@svs590

Description

@svs590

Hello!
I'm using clang-format 14 with option AlignAfterOpenBracket: BlockIndent and I found strange сlosing brackets behavior when close bracket or following qualifiers exceed ColumnLimit. This case appears when return-type + function-name + arguments can place on one line, but ) + qualifiers cannot.

Here is an example of .clang-format file:

# BasedOnStyle:  LLVM
AlignAfterOpenBracket: BlockIndent
AllowAllArgumentsOnNextLine: true
AllowShortFunctionsOnASingleLine: Empty
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping: 
  AfterFunction: false
ColumnLimit: 82
ContinuationIndentWidth: 4
IndentWidth: 4
PenaltyReturnTypeOnItsOwnLine: 41
PointerAlignment: Right
SpaceAroundPointerQualifiers: Both
TabWidth : 4
UseTab : Never
...

Here is an example when AlignAfterOpenBracket: BlockIndent works fine:

std::string some_function(const std::string &a, const std::string &b) noexcept {
    // Some code here...
}

std::string some_function(
    const std::string &a,
    const std::string &b,
    const std::string &c,
    const std::string &d
) noexcept {
    // Some code here...
}

void check_range(const std::size_t &idx) noexcept {
    // Some code here...
}

Everything is just as I expected.

But if I increase function name length or add some function attributes (e.g. MACRO), then I have weird behavior: only ) + qualifiers places on the next line.
Example:

void check_range_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(const std::size_t &idx
) {
    // Some code here...
}

void check_range_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(const std::size_t &idx
) noexcept {
    // Some code here...
}

CXX17_NODISCARD CXX20_CONSTEXPR void check_range(const std::size_t &idx
) noexcept {
    // Some code here...
}

Expected:

void check_range_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
    const std::size_t &idx
) {
    // Some code here...
}

void check_range_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
    const std::size_t &idx
) noexcept {
    // Some code here...
}

CXX17_NODISCARD CXX20_CONSTEXPR void check_range(
    const std::size_t &idx
) noexcept {
    // Some code here...
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions