Remove line break after single-statement if with clang-format

Viewed 897

I am trying to get clang-format to leave if-statements with one statement on the same line.

Example input:

if(is_finished) break;
if(foo) {
    // do something
}

clang-format output:

if(is_finished)
    break;
if(foo) {
    // do something
}

Wanted output:

if(is_finished) break;
if(foo) {
    // do something
}

None of the space related options seem to match this style.

current config:

---
Language: Cpp 
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: ForIndentation
SpaceBeforeParens: Never
BraceWrapping:
  AfterControlStatement: false
2 Answers
AllowShortIfStatementsOnASingleLine

And

AllowShortBlocksOnASingleLine

The first one does what you want, AllowShortBlocksOnASingleLine will also allow code such as

if (expression) { Something(); }
Related