Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
svs590 opened this issue May 15, 2022 · 5 comments
Labels
clang-format duplicate Resolved as duplicate

Comments

@svs590
Copy link

svs590 commented May 15, 2022

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...
}
@llvmbot
Copy link
Collaborator

llvmbot commented May 15, 2022

@llvm/issue-subscribers-clang-format

@martinling
Copy link

Also reported as #54808.

@KnoerleMan
Copy link

The whole thing gets even worse when you have a function call without parameters and reach the column limit around the parentheses:

image

In that case the formatting looks extremely strange.

Are there any other settings that prevent this?

@louwers
Copy link

louwers commented Apr 30, 2023

Look at this:

class Test {
  virtual void
  mergeOfflineRegions(const std::string &sideDatabasePath, std::function<void(expected<OfflineRegions, std::exception_ptr>)>);
};

It doesn't even take into account the ColumnLimit anymore!

@KnoerleMan

In that case the formatting looks extremely strange.

Are there any other settings that prevent this?

You can try setting a lower PenaltyExcessCharacter but it is not ideal

@Zingam
Copy link
Contributor

Zingam commented Nov 18, 2023

A duplicate of: #55731

@EugeneZelenko EugeneZelenko added the duplicate Resolved as duplicate label Nov 18, 2023
@EugeneZelenko EugeneZelenko closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

7 participants