<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Sorry for not reading the test cases first! Sorry for underestimation!</div><br><div><div>On Jun 3, 2013, at 9:30 , Daniel Jasper <<a href="mailto:djasper@google.com">djasper@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">No, this is excluded specifically (there is also a test for it). Basically we currently only remove the empty line if the next line is "}" or "};".</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, Jun 3, 2013 at 6:22 PM, Jordan Rose <span dir="ltr"><<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Does this also apply to if-else chains? I sometimes have a blank line before the next "} else if (...) {" that I wouldn't want removed.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Jun 3, 2013, at 9:16 , Daniel Jasper <<a href="mailto:djasper@google.com">djasper@google.com</a>> wrote:<br>
<br>
> Author: djasper<br>
> Date: Mon Jun 3 11:16:41 2013<br>
> New Revision: 183112<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=183112&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=183112&view=rev</a><br>
> Log:<br>
> Let clang-format remove empty lines before "}".<br>
><br>
> These lines almost never aid readability.<br>
><br>
> Before:<br>
> void f() {<br>
> int i; // some variable<br>
><br>
> }<br>
><br>
> After:<br>
> void f() {<br>
> int i; // some variable<br>
> }<br>
><br>
> Modified:<br>
> cfe/trunk/lib/Format/Format.cpp<br>
> cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
> cfe/trunk/unittests/Format/FormatTest.cpp<br>
><br>
> Modified: cfe/trunk/lib/Format/Format.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=183112&r1=183111&r2=183112&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=183112&r1=183111&r2=183112&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Format/Format.cpp (original)<br>
> +++ cfe/trunk/lib/Format/Format.cpp Mon Jun 3 11:16:41 2013<br>
> @@ -1592,6 +1592,11 @@ private:<br>
> bool InPPDirective) {<br>
> unsigned Newlines =<br>
> std::min(RootToken.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1);<br>
> + // Remove empty lines before "}" where applicable.<br>
> + if (<a href="http://RootToken.is">RootToken.is</a>(tok::r_brace) &&<br>
> + (!RootToken.Next ||<br>
> + (RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))<br>
> + Newlines = std::min(Newlines, 1u);<br>
> if (Newlines == 0 && !RootToken.IsFirst)<br>
> Newlines = 1;<br>
><br>
><br>
> Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=183112&r1=183111&r2=183112&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=183112&r1=183111&r2=183112&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)<br>
> +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jun 3 11:16:41 2013<br>
> @@ -54,7 +54,7 @@ private:<br>
> tok::question, tok::colon))<br>
> return false;<br>
> // If a && or || is found and interpreted as a binary operator, this set<br>
> - // of angles is like part of something like "a < b && c > d". If the<br>
> + // of angles is likely part of something like "a < b && c > d". If the<br>
> // angles are inside an expression, the ||/&& might also be a binary<br>
> // operator that was misinterpreted because we are parsing template<br>
> // parameters.<br>
><br>
> Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=183112&r1=183111&r2=183112&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=183112&r1=183111&r2=183112&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
> +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jun 3 11:16:41 2013<br>
> @@ -192,6 +192,53 @@ TEST_F(FormatTest, RemovesWhitespaceWhen<br>
> format("int a;\n \n\n int b;", 9, 0, getLLVMStyle()));<br>
> }<br>
><br>
> +TEST_F(FormatTest, RemovesEmptyLines) {<br>
> + EXPECT_EQ("class C {\n"<br>
> + " int i;\n"<br>
> + "};",<br>
> + format("class C {\n"<br>
> + " int i;\n"<br>
> + "\n"<br>
> + "};"));<br>
> +<br>
> + // Don't remove empty lines in more complex control statements.<br>
> + EXPECT_EQ("void f() {\n"<br>
> + " if (a) {\n"<br>
> + " f();\n"<br>
> + "\n"<br>
> + " } else if (b) {\n"<br>
> + " f();\n"<br>
> + " }\n"<br>
> + "}",<br>
> + format("void f() {\n"<br>
> + " if (a) {\n"<br>
> + " f();\n"<br>
> + "\n"<br>
> + " } else if (b) {\n"<br>
> + " f();\n"<br>
> + "\n"<br>
> + " }\n"<br>
> + "\n"<br>
> + "}"));<br>
> +<br>
> + // FIXME: This is slightly inconsistent.<br>
> + EXPECT_EQ("namespace {\n"<br>
> + "int i;\n"<br>
> + "}",<br>
> + format("namespace {\n"<br>
> + "int i;\n"<br>
> + "\n"<br>
> + "}"));<br>
> + EXPECT_EQ("namespace {\n"<br>
> + "int i;\n"<br>
> + "\n"<br>
> + "} // namespace",<br>
> + format("namespace {\n"<br>
> + "int i;\n"<br>
> + "\n"<br>
> + "} // namespace"));<br>
> +}<br>
> +<br>
> TEST_F(FormatTest, ReformatsMovedLines) {<br>
> EXPECT_EQ(<br>
> "template <typename T> T *getFETokenInfo() const {\n"<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br>
</div></div></blockquote></div><br></div>
</blockquote></div><br></body></html>