clang-format: Multiple statements in line

Hello,

I have code like that:

ierr = KSPDestroy(&ksp);CHKERRQ(ierr);

clang-format introduces a linebreak between the two statements. Is there a
possiblity to omit that?

My configuration, based on style LLVM:

AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false

(I've just set every remotely related option to don't break)

Thanks,
Florian

No, there isn’t.

No, there isn't.

Ok, thanks for that statement. Is this functionality planned somehow? Is there a bug tracker where I can file this as a wishlist item?

Best Regards,
Florian

Can you use a comma instead of semicolon to separate statements that you want on the same line?

-erik

Sure, there is bugs.llvm.org with a dedicated “Formatter” component.

However, the bar for adding such features is:

  • Large project with open style guide recommending it.
  • Person willing to contribute an maintain a patch.

Sure, there is bugs.llvm.org with a dedicated "Formatter" component.

However, the bar for adding such features is:
- Large project with open style guide recommending it.

Why that? Of course, I'm not suggesting to change the default setting, but I fail to understand how adding such a feature hurts if it doesn't change the default.

- Person willing to contribute an maintain a patch.

Sure.

Best Regards,
Florian

> Sure, there is bugs.llvm.org with a dedicated "Formatter" component.
>
> However, the bar for adding such features is:
> - Large project with open style guide recommending it.

Why that? Of course, I'm not suggesting to change the default setting, but
I fail to understand how adding such a feature hurts if it doesn't change
the default.

Every configuration flag has a certain cost. Among other things, this
includes:
- Style flags become less discoverable
- Maintenance increases when ensuring that all combinations of flags work
as expected

I'll try to put a more detailed explanation of the reasons on some
documentation page.

In essence, we'd rather support a stricter set of rules really well instead
trying to make clang-format work for everyone but doing a bad job of it.

I cannot speak for the developers, but adding a features – even when it is not default – has a cost in that you now have to make sure that it keeps working properly in face of future developement. And once you start allowing this you end up having a multitude of settings all not enabled by default that needs to be crosschecked.
Furthermore, people who contribute their own feature tend to disappear and not maintain it against new features. So we end up having either to ask the implementer of the new features to maintain this odd feature that has been orphaned or somebody else has to adopt it.

So in short, I think only features that are widely useful should get in (default or not) and I agree on the bar: if it is something that a widely distributed and used style guide recommends, it should be considered. In this particular case, my take is that multiple statements on the same line is something most style guides would discourage (or at most be silent about). Except in the special case of a for loop, clearly.

Ok, I understand your reason, though I do not agree :wink:

Another question on clang-format regarding initializer lists:

I want my list to have one initializer per line, with the break after the comma.

ConstructorInitializerAllOnOneLineOrOnePerLine: true does this, but only if the unbroken list is longer than ColumnLimit

Is there a way to always break the initializer list after each entry? I understand the WebKit style guide to demand that:

Constructors for C++ classes should initialize all of their members using
C++ initializer syntax. Each member (and superclass) should be indented on
a separate line, with the colon or comma preceding the member on that line.

http://www.webkit.org/coding/coding-style.html

Best Regards,
Florian

No, there is no such option. For webkit style we don’t really need it as we can either link it to the comma placement or just keep the authors line break (as webkit doesn’t have a columnlimit).