[PATCH] D93846: [clang-format] PR16518 Add flag to suppress empty line insertion before access modifier

Albertas Vyšniauskas via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 28 09:32:10 PST 2020


thezbyg marked 10 inline comments as done.
thezbyg added inline comments.


================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:1220
+  if (Style.InsertEmptyLineBeforeAccessModifier && PreviousLine &&
+      PreviousLine->Last->isOneOf(tok::semi, tok::r_brace) &&
       RootToken.isAccessSpecifier() && RootToken.NewlinesBefore == 1)
----------------
curdeius wrote:
> Just thinking out loud, but shouldn't we just check that `PreviousLine->Last->isNot(tok::l_brace)`?
> Could you please add a test with comments before access modifiers?
No previous line token check is necessary if it is acceptable to remove empty lines in situations where EmptyLineBeforeAccessModifier=true would not add empty line.

Without any additional tests formatting the following code with EmptyLineBeforeAccessModifier=true:

```
struct foo {
private:
  int i;
}
```
would not add any empty lines, but formatting this code with EmptyLineBeforeAccessModifier=false:

```
struct foo {

private:
  int i;
}
```
would remove empty line before modifier.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93846/new/

https://reviews.llvm.org/D93846



More information about the cfe-commits mailing list