Open brace on newline after multiline stmt: Clang-Format

I’m looking for a rule in Clang Format that allows me to have an opening brace on a new line only when the statement that precedes it spans multiple lines.

For example:

void foo() {  // single line

void bar(int aaaaaaaaaaaaaaaaaaaa
         int bbbbbbbbbbbbbbbbbbbb)
{  // declaration of bar spanned multiple lines, brace on newline.

for (int i = 0;
     i < 10; ++i)
{  // for loop spanned multiple lines, so brace on newline.

Is such a rule available in Clang Format?

Yes, such a rule is available in Clang Format. You can use the AllowAllParametersOfDeclarationOnNextLine option in the BraceWrapping configuration to achieve this. Here’s an example configuration:

  AfterFunction: true
  AfterControlStatement: true
  AfterClass: true
  AllowAllParametersOfDeclarationOnNextLine: true

With this configuration, braces will be on the same line for single-line statements and on the next line for multi-line statements.