Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang-Format: Open brace on newline after multiline statement

I'm looking for a way to conditionally set the opening brace on a newline only after the statement that preceded it spanned 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 there any rule that allows this in clang format? I can't seem to find one.

like image 658
Keltek Avatar asked Jan 24 '26 09:01

Keltek


1 Answers

.clang-format

BraceWrapping:
  AfterControlStatement: MultiLine

Feature proposal and merged

like image 117
Romain Laneuville Avatar answered Jan 25 '26 23:01

Romain Laneuville



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!