]> granicus.if.org Git - clang/commitdiff
clang-format: Don't remove empty lines at the start of namespaces.
authorDaniel Jasper <djasper@google.com>
Fri, 21 Mar 2014 13:03:33 +0000 (13:03 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 21 Mar 2014 13:03:33 +0000 (13:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204462 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index e3e959ef33522461fedc8beb1389f4e84300e9c2..976b5466815ec224959ddd781d16b31d9780a4ab 100644 (file)
@@ -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.
index 42b9e856e9772d35effad346d3f10172610f9f00..dafaac45692de4a907c8f641f8bd15b958b9d202 100644 (file)
@@ -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"