Having the following structs definitions:
struct city
{
};
struct country
{
};
I would like clang-format to format it for me like
struct city {};
struct country {};
But it seems that if you want an empty struct / class to be in a single line, then you have to accept that the opening curly brace { always stays in the same line as struct or class. To do so, set
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: false
Then you will have
class A {};
class B {
void foo() {}
};
If you want to achieve something like
class A {};
class B
{
void foo() {}
};
Then clang-format cannot do that as far as I know.
I will discuss some related options below.
First, assume we have set
BreakBeforeBraces: Custom
Without this, all the options that follow are ignored.
Then,
BraceWrapping:
AfterClass: false
would result in
class Foo {
// data members and member functions
};
In contrast,
BraceWrapping:
AfterClass: true
would lead to
class Foo
{
// data members and member functions
};
Now, given AfterClass is set to true, then SplitEmptyRecord determines whether an empty class will be split to two lines.
BraceWrapping:
SplitEmptyRecord: false
would result in
class EmptyClass
{};
while
SplitEmptyRecord: true
would give you
class EmptyClass
{
};
Sadly, none of these specifically address the problem. Will some options like AllowShortStructOnASingleLine be added in ? Or it is hard to implement ?