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.
}
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: