From 03e69f5cb43cef2e4e11b2f607b9e8db2e275383 Mon Sep 17 00:00:00 2001 From: Krasimir Georgiev Date: Tue, 27 Mar 2018 13:14:29 +0000 Subject: [PATCH] Revert "[clang-format] Remove empty lines before }[;] // comment" This reverts commit r327861. The empty line before namespaces is desired in some places. We need a better approach to handle this. llvm-svn: 328621 --- clang/lib/Format/UnwrappedLineFormatter.cpp | 6 +----- clang/unittests/Format/FormatTest.cpp | 16 ++-------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index b0da002..2ce39fb 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -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) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 36ed318..c125028 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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; -- 2.7.4