]> granicus.if.org Git - clang/commitdiff
Revert "[clang-format] Remove empty lines before }[;] // comment"
authorKrasimir Georgiev <krasimir@google.com>
Tue, 27 Mar 2018 13:14:29 +0000 (13:14 +0000)
committerKrasimir Georgiev <krasimir@google.com>
Tue, 27 Mar 2018 13:14:29 +0000 (13:14 +0000)
This reverts commit r327861.

The empty line before namespaces is desired in some places. We need a
better approach to handle this.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328621 91177308-0d34-0410-b5e6-96231b3b80d8

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

index b0da0028bf3a4b0805fc250da6656b26db8f54a8..2ce39fb04c6cfe3ae9061c8adf56586e5bacdd56 100644 (file)
@@ -1133,12 +1133,8 @@ void UnwrappedLineFormatter::formatFirstToken(const AnnotatedLine &Line,
       std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);
   // Remove empty lines before "}" where applicable.
   if (RootToken.is(tok::r_brace) &&
-      // Look for "}", "} // comment", "};" or "}; // comment".
       (!RootToken.Next ||
-       (RootToken.Next->is(tok::comment) && !RootToken.Next->Next) ||
-       (RootToken.Next->is(tok::semi) &&
-        (!RootToken.Next->Next || (RootToken.Next->Next->is(tok::comment) &&
-                                   !RootToken.Next->Next->Next)))))
+       (RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))
     Newlines = std::min(Newlines, 1u);
   // Remove empty lines at the start of nested blocks (lambdas/arrow functions)
   if (PreviousLine == nullptr && Line.Level > 0)
index 36ed318eeccad71937ba2ec002eaea1900477cb1..c1250283a131ab2c3cac189c07ffaf2acd3cd0e6 100644 (file)
@@ -276,6 +276,7 @@ TEST_F(FormatTest, RemovesEmptyLines) {
                    "\n"
                    "}"));
 
+  // FIXME: This is slightly inconsistent.
   FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle();
   LLVMWithNoNamespaceFix.FixNamespaceComments = false;
   EXPECT_EQ("namespace {\n"
@@ -294,25 +295,12 @@ TEST_F(FormatTest, RemovesEmptyLines) {
                    "}"));
   EXPECT_EQ("namespace {\n"
             "int i;\n"
-            "};",
-            format("namespace {\n"
-                   "int i;\n"
-                   "\n"
-                   "};"));
-  EXPECT_EQ("namespace {\n"
-            "int i;\n"
+            "\n"
             "} // namespace",
             format("namespace {\n"
                    "int i;\n"
                    "\n"
                    "}  // namespace"));
-  EXPECT_EQ("namespace {\n"
-            "int i;\n"
-            "}; // namespace",
-            format("namespace {\n"
-                   "int i;\n"
-                   "\n"
-                   "};  // namespace"));
 
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;