r204462 - clang-format: Don't remove empty lines at the start of namespaces.

Daniel Jasper djasper at google.com
Fri Mar 21 06:03:33 PDT 2014


Author: djasper
Date: Fri Mar 21 08:03:33 2014
New Revision: 204462

URL: http://llvm.org/viewvc/llvm-project?rev=204462&view=rev
Log:
clang-format: Don't remove empty lines at the start of namespaces.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=204462&r1=204461&r2=204462&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Mar 21 08:03:33 2014
@@ -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.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=204462&r1=204461&r2=204462&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Mar 21 08:03:33 2014
@@ -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"





More information about the cfe-commits mailing list