From: Daniel Jasper Date: Fri, 21 Mar 2014 13:03:33 +0000 (+0000) Subject: clang-format: Don't remove empty lines at the start of namespaces. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59aca272388cc1b98e6e0545cad4a0d4ddf9476a;p=clang clang-format: Don't remove empty lines at the start of namespaces. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204462 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index e3e959ef33..976b546681 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -889,7 +889,8 @@ private: 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. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 42b9e856e9..dafaac4569 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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"