<div class="gmail_quote">On Sun, Jan 13, 2013 at 10:04 PM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div class="gmail_default">Do we have a style (guide) that says you can't put a space between ")" and "{"?</div></div></blockquote><div><br></div><div>I would expect style guides to implicitly include them in whatever they say about casts.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 14, 2013 at 1:18 AM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div>On Sun, Jan 13, 2013 at 12:01 AM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: djasper<br>
Date: Sun Jan 13 02:01:36 2013<br>
New Revision: 172349<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=172349&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=172349&view=rev</a><br>
Log:<br>
Improve identification of c-style casts.<br>
<br>
A ")" before any of "=", "{" or ";" won't be a cast. This fixes issues<br>
with the formatting of unnamed parameters.<br></blockquote><div><br></div></div><div>What about C99 compound literals? e.g. (struct S){1, 2, 3}</div><div><div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



Before: void f(int *){}<br>
After:  void f(int *) {}<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=172349&r1=172348&r2=172349&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172349&r1=172348&r2=172349&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Sun Jan 13 02:01:36 2013<br>
@@ -976,7 +976,11 @@<br>
           Current.Type = TT_BlockComment;<br>
       } else if (Current.is(tok::r_paren) &&<br>
                  (Current.Parent->Type == TT_PointerOrReference ||<br>
-                  Current.Parent->Type == TT_TemplateCloser)) {<br>
+                  Current.Parent->Type == TT_TemplateCloser) &&<br>
+                 (Current.Children.empty() ||<br>
+                  (Current.Children[0].isNot(tok::equal) &&<br>
+                   Current.Children[0].isNot(tok::semi) &&<br>
+                   Current.Children[0].isNot(tok::l_brace)))) {<br>
         // FIXME: We need to get smarter and understand more cases of casts.<br>
         Current.Type = TT_CastRParen;<br>
       } else if (Current.is(tok::at) && Current.Children.size()) {<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=172349&r1=172348&r2=172349&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172349&r1=172348&r2=172349&view=diff</a><br>



==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Jan 13 02:01:36 2013<br>
@@ -1045,9 +1045,6 @@<br>
   verifyFormat("A<int **> a;");<br>
   verifyFormat("A<int *, int *> a;");<br>
   verifyFormat("A<int **, int **> a;");<br>
-  verifyFormat("Type *A = static_cast<Type *>(P);");<br>
-  verifyFormat("Type *A = (Type *)P;");<br>
-  verifyFormat("Type *A = (vector<Type *, int *>)P;");<br>
<br>
   verifyFormat(<br>
       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"<br>
@@ -1062,6 +1059,25 @@<br>
   verifyGoogleFormat("int a = b ? *c : *d;");<br>
 }<br>
<br>
+TEST_F(FormatTest, FormatsCasts) {<br>
+  verifyFormat("Type *A = static_cast<Type *>(P);");<br>
+  verifyFormat("Type *A = (Type *)P;");<br>
+  verifyFormat("Type *A = (vector<Type *, int *>)P;");<br>
+  verifyFormat("int a = (int)(2.0f);");<br>
+<br>
+  // FIXME: These also need to be identified.<br>
+  verifyFormat("int a = (int) 2.0f;");<br>
+  verifyFormat("int a = (int) * b;");<br>
+<br>
+  // These are not casts.<br>
+  verifyFormat("void f(int *) {}");<br>
+  verifyFormat("void f(int *);");<br>
+  verifyFormat("void f(int *) = 0;");<br>
+  verifyFormat("void f(SmallVector<int>) {}");<br>
+  verifyFormat("void f(SmallVector<int>);");<br>
+  verifyFormat("void f(SmallVector<int>) = 0;");<br>
+}<br>
+<br>
 TEST_F(FormatTest, FormatsFunctionTypes) {<br>
   // FIXME: Determine the cases that need a space after the return type and fix.<br>
   verifyFormat("A<bool()> 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></div></div><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br>