<div style="font-family: arial, helvetica, sans-serif; font-size: 10pt"><div dir="ltr"><div class="gmail_default" style>Well, this patch only consolidates the "int f() {}" and "int* f() {}" cases, so it is a step into the right direction. If we implement the line break you are suggesting, we should do so deliberately ;-).</div>
<div class="gmail_default" style><br></div><div class="gmail_default" style>clang-format currently formats like (assuming "bar" does not fit on the first line):</div><div class="gmail_default" style><br></div><div class="gmail_default" style>
<div style="font-family:arial,sans-serif;font-size:13px"><font face="Courier">int </font><span style="font-family:Courier">foo(</span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:Courier">    int bar,</span></div>
<div style="font-family:arial,sans-serif;font-size:13px"><font face="Courier">    int baz);</font></div><div style="font-family:arial,sans-serif;font-size:13px"><font face="Courier"><br></font></div><div style="font-family:arial,sans-serif;font-size:13px">
<font face="Courier">int *</font><span style="font-family:Courier">foo2(</span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:Courier">    int bar);</span></div><div style="font-family:arial,sans-serif;font-size:13px">
<span style="font-family:Courier"><br></span></div><div style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial;font-size:small">I personally would prefer that over the other solution, but it is obviously a matter of taste (I didn't find anything in the style guide). </span><span style="font-family:Courier"><br>
</span></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 2, 2013 at 7:45 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"><div style="word-wrap:break-word"><div>Hm. We do this deliberately in LLVM sometimes, though, when we're pushing up against the 80-column limit.</div>
<div><br></div><div><font face="Courier">int</font></div><div><font face="Courier">foo(int bar,</font></div><div><font face="Courier">    int baz);</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">int *</font></div>
<div><font face="Courier">foo2(int bar);</font></div><div><br></div><div>I grant you that this looks weird, but IMHO it's better than the alternative:</div><div><br></div><div><div><font face="Courier">int </font><span style="font-family:Courier">foo(</span></div>
<div><span style="font-family:Courier">  int bar,</span></div><div><font face="Courier">  int baz);</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">int *</font><span style="font-family:Courier">foo2(</span></div>
<div><span style="font-family:Courier">  int bar);</span></div></div><div><font face="Courier"><br></font></div><div>What happens in these cases?</div><span class="HOEnZb"><font color="#888888"><div>Jordan</div></font></span><div>
<div class="h5"><div><br></div><br><div><div><div>On Jan 2, 2013, at 0:44 , Daniel Jasper <<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>> wrote:</div><br><blockquote type="cite">Author: djasper<br>
Date: Wed Jan  2 02:44:14 2013<br>New Revision: 171357<br><br>URL: <a href="http://llvm.org/viewvc/llvm-project?rev=171357&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=171357&view=rev</a><br>Log:<br>
Don't break after pointer or reference specifier.<br><br>This fixes <a href="http://llvm.org/PR14717" target="_blank">llvm.org/PR14717</a>.<br>Buggy format:<br>TypeSpecDecl *<br>    TypeSpecDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,<br>
                         IdentifierInfo *II, Type *T) {<br><br>Now changed to:<br>TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,<br>                                   SourceLocation L, IdentifierInfo *II,<br>
                                   Type *T) {<br><br>Modified:<br>    cfe/trunk/lib/Format/Format.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=171357&r1=171356&r2=171357&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=171357&r1=171356&r2=171357&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/lib/Format/Format.cpp (original)<br>+++ cfe/trunk/lib/Format/Format.cpp Wed Jan  2 02:44:14 2013<br>@@ -660,8 +660,7 @@<br>     for (int i = 1, e = Line.Tokens.size(); i != e; ++i) {<br>
       TokenAnnotation &Annotation = Annotations[i];<br><br>-      Annotation.CanBreakBefore =<br>-          canBreakBetween(Line.Tokens[i - 1], Line.Tokens[i]);<br>+      Annotation.CanBreakBefore = canBreakBefore(i);<br>
<br>       if (Annotation.Type == TokenAnnotation::TT_CtorInitializerColon) {<br>         Annotation.MustBreakBefore = true;<br>@@ -896,7 +895,13 @@<br>     return true;<br>   }<br><br>-  bool canBreakBetween(const FormatToken &Left, const FormatToken &Right) {<br>
+  bool canBreakBefore(unsigned i) {<br>+    if (Annotations[i - 1].Type == TokenAnnotation::TT_PointerOrReference ||<br>+        Annotations[i].Type == TokenAnnotation::TT_ConditionalExpr) {<br>+      return false;<br>+    }<br>
+    const FormatToken &Left = Line.Tokens[i - 1];<br>+    const FormatToken &Right = Line.Tokens[i];<br>     if (<a href="http://Right.Tok.is" target="_blank">Right.Tok.is</a>(tok::r_paren) || <a href="http://Right.Tok.is" target="_blank">Right.Tok.is</a>(tok::l_brace) ||<br>
         <a href="http://Right.Tok.is" target="_blank">Right.Tok.is</a>(tok::comment) || <a href="http://Right.Tok.is" target="_blank">Right.Tok.is</a>(tok::greater))<br>       return false;<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=171357&r1=171356&r2=171357&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171357&r1=171356&r2=171357&view=diff</a><br>
==============================================================================<br>--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan  2 02:44:14 2013<br>@@ -682,6 +682,16 @@<br>
   verifyGoogleFormat("A<int**, int**> a;");<br> }<br><br>+TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) {<br>+  verifyFormat(<br>+      "int *someFunction(int LoooooooooooooooongParam1,\n"<br>
+      "                  int LoooooooooooooooongParam2) {\n}");<br>+  verifyFormat(<br>+      "TypeSpecDecl *TypeSpecDecl::Create(ASTContext &C, DeclContext *DC,\n"<br>+      "                                   SourceLocation L, IdentifierIn *II,\n"<br>
+      "                                   Type *T) {\n}");<br>+}<br>+<br> TEST_F(FormatTest, LineStartsWithSpecialCharacter) {<br>   verifyFormat("(a)->b();");<br>   verifyFormat("--a;");<br>
<br><br>_______________________________________________<br>cfe-commits mailing list<br><a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">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>
</blockquote></div><br></div></div></div></div></blockquote></div><br></div></div>