1

I'm trying to format classes inside namespaces in the following way (BreakBeforeBraces: Allman):

namespace test_a::test_b
{

struct A
{
    int a;
    int b;
};

}  // namespace test_a::test_b

but clang format keeps changing it to

namespace test_a::test_b
{
struct A
{
    int a;
    int b;
};

}  // namespace test_a::test_b

The workaround in this question works only with configurations like BasedOnStyle: Google no brakes before opening braces for example

namespace test_a::test_b {

struct A {
    int a;
    int b;
};

}  // namespace test_a::test_b

Same for this answer

I want clang-format to always add an empty line after namespace opening brace and before closing brace, is that possible?

For clarity, this is the clang-format I use

---
BasedOnStyle: Google
AccessModifierOffset: -4
AlignConsecutiveDeclarations: 'true'
BinPackArguments: 'false'
BinPackParameters: 'false'
IndentWidth: '4'
AlignConsecutiveAssignments: 'true'
ColumnLimit: 120
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
...
DontCareBear
  • 825
  • 2
  • 11
  • 25

1 Answers1

2

clang format can't do that specifically for namespace for the moment, but you can use KeepEmptyLinesAtTheStartOfBlocks to put empty line for all blocks. what if you use BreakBeforeBraces: Custom ?

Tom Penard
  • 141
  • 8
  • I tried "BreakBeforeBraces: Custom". it's only giving you the freedom to choose where to break, but it keeps removing spaces. So this is not the answer, but "KeepEmptyLinesAtTheStartOfBlocks" is working splendidly, so thank you! – DontCareBear Oct 26 '21 at 10:21