r327861 - [clang-format] Remove empty lines before }[;] // comment
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 19 08:33:40 PDT 2018
Author: krasimir
Date: Mon Mar 19 08:33:40 2018
New Revision: 327861
URL: http://llvm.org/viewvc/llvm-project?rev=327861&view=rev
Log:
[clang-format] Remove empty lines before }[;] // comment
Summary:
This addresses bug 36766 and a FIXME in tests about empty lines before
`}[;] // comment` lines.
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D44631
Modified:
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=327861&r1=327860&r2=327861&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Mon Mar 19 08:33:40 2018
@@ -1133,8 +1133,12 @@ void UnwrappedLineFormatter::formatFirst
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::semi) && !RootToken.Next->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)))))
Newlines = std::min(Newlines, 1u);
// Remove empty lines at the start of nested blocks (lambdas/arrow functions)
if (PreviousLine == nullptr && Line.Level > 0)
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=327861&r1=327860&r2=327861&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Mar 19 08:33:40 2018
@@ -276,7 +276,6 @@ TEST_F(FormatTest, RemovesEmptyLines) {
"\n"
"}"));
- // FIXME: This is slightly inconsistent.
FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle();
LLVMWithNoNamespaceFix.FixNamespaceComments = false;
EXPECT_EQ("namespace {\n"
@@ -295,12 +294,25 @@ TEST_F(FormatTest, RemovesEmptyLines) {
"}"));
EXPECT_EQ("namespace {\n"
"int i;\n"
- "\n"
+ "};",
+ format("namespace {\n"
+ "int i;\n"
+ "\n"
+ "};"));
+ EXPECT_EQ("namespace {\n"
+ "int i;\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;
More information about the cfe-commits
mailing list