[PATCH] D44631: [clang-format] Remove empty lines before }[; ] // comment
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 19 08:34:04 PDT 2018
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.
This addresses bug 36766 and a FIXME in tests about empty lines before
`}[;] // comment` lines.
Repository:
rC Clang
https://reviews.llvm.org/D44631
Files:
lib/Format/UnwrappedLineFormatter.cpp
unittests/Format/FormatTest.cpp
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -276,7 +276,6 @@
"\n"
"}"));
- // FIXME: This is slightly inconsistent.
FormatStyle LLVMWithNoNamespaceFix = getLLVMStyle();
LLVMWithNoNamespaceFix.FixNamespaceComments = false;
EXPECT_EQ("namespace {\n"
@@ -295,12 +294,25 @@
"}"));
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;
Index: lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -1133,8 +1133,12 @@
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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44631.138941.patch
Type: text/x-patch
Size: 2215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180319/c3725427/attachment.bin>
More information about the cfe-commits
mailing list