[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:38:03 PDT 2018
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC327861: [clang-format] Remove empty lines before }[;] // comment (authored by krasimir, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D44631?vs=138941&id=138942#toc
Repository:
rC Clang
https://reviews.llvm.org/D44631
Files:
lib/Format/UnwrappedLineFormatter.cpp
unittests/Format/FormatTest.cpp
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)
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44631.138942.patch
Type: text/x-patch
Size: 2215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180319/2f35734a/attachment.bin>
More information about the cfe-commits
mailing list