Wrap brace (and/or parentheses) after long function signature in clang-format

Viewed 441

I'm trying to achieve the following format for short functions:

void shortFunctionDecl(int x, int y) {
    // ...
}

But if the line is too long, I would like it to overflow like this (and not bin pack the arguments)

void longerFunctionDecl(
    int longName, 
    int longName2,
    int longName3
) { // I would also be ok if the paren were on the previous line and the brace on this one
    // ...
}

Currently code ends up like this and it's annoying to read

void longerFunctionDecl(
    int longName, 
    int longName2,
    int longName3) { 
    // code is at the same indentation level as the args, hard to read.
}

I've been trying to place around with some of the BraceWrapping settings but it looks like there are only Multiline settings for control statements. Is it possible to do what I want in clang-format? FWIW, it seems like the parenthesis breaks are not possible but I wonder if the brace breaks might be? Really not sure.

Here's my .clang-format file. I've marked the relevant section, but included the entire thing for completeness.

BasedOnStyle: Google
IndentWidth: 4
TabWidth: 4
UseTab: Always
ColumnLimit: 120
AccessModifierOffset: -3
# Relevant portion:
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
BinPackParameters: false
AlignAfterOpenBracket: AlwaysBreak
AllowAllArgumentsOnNextLine: false
1 Answers

A new option AlignAfterOpenBracket: BlockIndent was added (2022-01-17) in the approved code review https://reviews.llvm.org/D109557, which is in clang format LLVM 14.0.0-rc1 or later.

AlignAfterOpenBracket: BlockIndent: If set, it will always break after an
open bracket, if the parameters don't fit on a single line. Closing brackets
will be placed on a new line.
Related