]> granicus.if.org Git - clang/commitdiff
clang-format: Correctly understand arrays of pointers.
authorDaniel Jasper <djasper@google.com>
Tue, 8 Apr 2014 13:07:41 +0000 (13:07 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 8 Apr 2014 13:07:41 +0000 (13:07 +0000)
Before:
  A<int * []> a;

After:
  A<int *[]> a;

This fixes llvm.org/PR19360.

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

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

index 0034235c32d023fbe372264cecd0b5ebc0fdc883..f890af33debb306d054825a66dcd66f91dcd2f2a 100644 (file)
@@ -245,7 +245,7 @@ private:
           StartsObjCMethodExpr = false;
           Left->Type = TT_Unknown;
         }
-        if (StartsObjCMethodExpr) {
+        if (StartsObjCMethodExpr && CurrentToken->Previous != Left) {
           CurrentToken->Type = TT_ObjCMethodExpr;
           // determineStarAmpUsage() thinks that '*' '[' is allocating an
           // array of pointers, but if '[' starts a selector then '*' is a
index d59ed6c0aff19984bf217831078dd3ffe48ed83b..c7bd44c12d2931c0eecbc4c724d00cf570c1bf54 100644 (file)
@@ -4473,6 +4473,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("A<int *> a;");
   verifyIndependentOfContext("A<int **> a;");
   verifyIndependentOfContext("A<int *, int *> a;");
+  verifyIndependentOfContext("A<int *[]> a;");
   verifyIndependentOfContext(
       "const char *const p = reinterpret_cast<const char *const>(q);");
   verifyIndependentOfContext("A<int **, int **> a;");