I'm trying to configure clang-format so that usually braces will start on their own line:
void func()
{
if (...)
{
printf("Ta Da\n");
}
}
But I want it to be so when braces are empty, it will be kept in a single line. (Mainly used for ctors):
Bar::Bar(int val):
_val(val)
{}
currently it will look like this:
Bar::Bar(int val):
_val(val)
{
}
Any ideas?
(Edited to make the situation clearer)
UPDATE: Hurray! It is now possible with Clang 5.0 or later with custom BreakBeforeBraces
.
See SplitEmptyFunction
in the documentation.
Configuration example:
BreakBeforeBraces: Custom
BraceWrapping:
SplitEmptyFunction: false
Unfortunately, it is not possible to achieve with Clang 4.0 the current clang-format options (as of Clang 4.0).
Source: I had the same question. After studying every documented option, and many tweaking attempts, I could not achieve this. In my experience, clang-format is just not as flexible as one would hope. As soon as you want to step out of the predefined styles and tweak things to your liking, it just does not cut it.
I used combination of "AllowShortFunctionsOnASingleLine": true, and "BreakBeforeBraces": "Allman", to get it to one line when declaring empty constructors etc..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With