]> granicus.if.org Git - clang/commitdiff
Fix regression in formatting pointer types.
authorDaniel Jasper <djasper@google.com>
Wed, 23 Jan 2013 11:15:14 +0000 (11:15 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 23 Jan 2013 11:15:14 +0000 (11:15 +0000)
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; }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173252 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index 90bcf6feb773115d6e2ed39eabb97a0af9a5dba4..36bf53d9a7ae54b488e21326efbb6816aba0e6ac 100644 (file)
@@ -1260,6 +1260,8 @@ private:
     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 @@ private:
 
     // 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;
index 114359d04d1b8d9e51924a05bebbdc0cd98b5723..44f91c7fb0be264e93f822f0744f58af523bdf14 100644 (file)
@@ -1288,6 +1288,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   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;");