Skip to content

Commit

Permalink
clang-format: Don't remove empty lines at the start of namespaces.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204462 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
djasper-gh committed Mar 21, 2014
1 parent 264449a commit 59aca27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,8 @@ class UnwrappedLineFormatter {
Newlines = 1;

// Remove empty lines after "{".
if (PreviousLine && PreviousLine->Last->is(tok::l_brace))
if (PreviousLine && PreviousLine->Last->is(tok::l_brace) &&
PreviousLine->First->isNot(tok::kw_namespace))
Newlines = 1;

// Insert extra new line before access specifiers.
Expand Down
10 changes: 10 additions & 0 deletions unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ TEST_F(FormatTest, RemovesEmptyLines) {
"\n"
"};"));

// Don't remove empty lines at the start of namespaces.
EXPECT_EQ("namespace N {\n"
"\n"
"int i;\n"
"}",
format("namespace N {\n"
"\n"
"int i;\n"
"}"));

// Remove empty lines at the beginning and end of blocks.
EXPECT_EQ("void f() {\n"
" if (a) {\n"
Expand Down

0 comments on commit 59aca27

Please sign in to comment.