summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-22 11:46:26 +0000
committerDaniel Jasper <djasper@google.com>2013-01-22 11:46:26 +0000
commit0b8206029ba79c78022881130ccb69862eaf60f2 (patch)
treea2d96a6519ed1a68e26ddd3df9251f878774ac84
parent81f0b331dc977f78284cc98071c863565c04c472 (diff)
downloadbcm5719-llvm-0b8206029ba79c78022881130ccb69862eaf60f2.tar.gz
bcm5719-llvm-0b8206029ba79c78022881130ccb69862eaf60f2.zip
Fix "*" formatting when creating arrays of pointers.
Before: A = new int * [10](); After: A = new int *[10](); llvm-svn: 173150
-rw-r--r--clang/lib/Format/Format.cpp10
-rw-r--r--clang/unittests/Format/FormatTest.cpp3
2 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 05c96bd38da..e9ff3c9b129 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -958,6 +958,13 @@ public:
while (CurrentToken != NULL) {
if (CurrentToken->is(tok::r_square)) {
+ if (!CurrentToken->Children.empty() &&
+ CurrentToken->Children[0].is(tok::l_paren)) {
+ // An ObjC method call can't be followed by an open parenthesis.
+ // FIXME: Do we incorrectly label ":" with this?
+ StartsObjCMethodExpr = false;
+ Left->Type = TT_Unknown;
+ }
if (StartsObjCMethodExpr)
objCSelector.markEnd(*CurrentToken);
Left->MatchingParen = CurrentToken;
@@ -1325,6 +1332,9 @@ private:
if (NextToken == NULL)
return TT_Unknown;
+ if (NextToken->is(tok::l_square) && NextToken->Type != TT_ObjCMethodExpr)
+ return TT_PointerOrReference;
+
if (PrevToken->is(tok::l_paren) || PrevToken->is(tok::l_square) ||
PrevToken->is(tok::l_brace) || PrevToken->is(tok::comma) ||
PrevToken->is(tok::kw_return) || PrevToken->is(tok::colon) ||
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ba6d7519c6c..0c6385b7a16 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -1338,6 +1338,9 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("if (*b[i])");
verifyFormat("if (int *a = (&b))");
verifyFormat("while (int *a = &b)");
+
+ verifyFormat("A = new SomeType *[Length]();");
+ verifyGoogleFormat("A = new SomeType* [Length]();");
}
TEST_F(FormatTest, FormatsCasts) {
OpenPOWER on IntegriCloud