From 2355cebe3847acd4ce175e3a88788b8effd93c6e Mon Sep 17 00:00:00 2001
From: Nico Weber <nicolasweber@gmx.de>
Date: Sat, 12 Jan 2013 05:47:16 +0000
Subject: [PATCH] Formatter: * and & are binary operators after ) and ].

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172302 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Format/Format.cpp           | 3 ++-
 unittests/Format/FormatTest.cpp | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 5140639d009..e4dc2913126 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -969,7 +969,8 @@ private:
         Tok.Parent->Type == TT_CastRParen)
       return TT_UnaryOperator;
 
-    if (PrevToken.Tok.isLiteral() || NextToken.Tok.isLiteral() ||
+    if (PrevToken.Tok.isLiteral() || PrevToken.Tok.is(tok::r_paren) ||
+        PrevToken.Tok.is(tok::r_square) || NextToken.Tok.isLiteral() ||
         NextToken.Tok.is(tok::plus) || NextToken.Tok.is(tok::minus) ||
         NextToken.Tok.is(tok::plusplus) || NextToken.Tok.is(tok::minusminus) ||
         NextToken.Tok.is(tok::tilde) || NextToken.Tok.is(tok::exclaim) ||
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 9106a1fc7f3..e5dbd630202 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -1014,6 +1014,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("a * -b;");
   verifyFormat("a * ++b;");
   verifyFormat("a * --b;");
+  verifyFormat("a[4] * b;");
+  verifyFormat("f() * b;");
   verifyFormat("int *pa = (int *)&a;");
 
   verifyFormat("InvalidRegions[*R] = 0;");
-- 
GitLab