Search code examples
c++clang-format

clang-format: How to keep line feeds after access modifiers?


What I'm getting:

class Foo
{
public:
  int stuff;

  int otherStuff;
}

What I'd like to get (or preserve) is:

class Foo
{
public:

  int stuff;

  int otherStuff;
}

How can I prevent clang-format from removing my line feeds after access modifier indentation?


Solution

  • Add this in .clang-format (see here, starting clang 13) :

    EmptyLineAfterAccessModifier: Always
    

    It will do for private, protected and public.

    Just for info there is also EmptyLineBeforeAccessModifier