[cfe-commits] r173252 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp

Daniel Jasper djasper at google.com
Wed Jan 23 03:15:14 PST 2013


Author: djasper
Date: Wed Jan 23 05:15:14 2013
New Revision: 173252

URL: http://llvm.org/viewvc/llvm-project?rev=173252&view=rev
Log:
Fix regression in formatting pointer types.

We will need a more principled solution, but we should not leave this
unfixed until we come up with one.

Before: void f() { int * a; }
After:  void f() { int *a; }

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=173252&r1=173251&r2=173252&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 23 05:15:14 2013
@@ -1260,6 +1260,8 @@
     if (getPrecedence(Current) == prec::Assignment ||
         Current.is(tok::kw_return) || Current.is(tok::kw_throw))
       IsRHS = true;
+    if (Current.is(tok::l_paren) && !Line.MustBeDeclaration)
+      IsRHS = true;
 
     if (Current.Type == TT_Unknown) {
       if (Current.is(tok::star) || Current.is(tok::amp)) {
@@ -1370,7 +1372,7 @@
 
     // It is very unlikely that we are going to find a pointer or reference type
     // definition on the RHS of an assignment.
-    if (IsRHS || !Line.MustBeDeclaration)
+    if (IsRHS)
       return TT_BinaryOperator;
 
     return TT_PointerOrReference;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173252&r1=173251&r2=173252&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 23 05:15:14 2013
@@ -1288,6 +1288,7 @@
   verifyFormat("int a = *b;");
   verifyFormat("int a = *b * c;");
   verifyFormat("int a = b * *c;");
+  verifyFormat("void f() { int *a = b * c; }");
   verifyFormat("int main(int argc, char **argv) {}");
   verifyFormat("return 10 * b;");
   verifyFormat("return *b * *c;");





More information about the cfe-commits mailing list