]> granicus.if.org Git - clang/commitdiff
clang-format: Re-add code path deleted in r253873 and add missing test.
authorDaniel Jasper <djasper@google.com>
Mon, 23 Nov 2015 19:11:45 +0000 (19:11 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 23 Nov 2015 19:11:45 +0000 (19:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253900 91177308-0d34-0410-b5e6-96231b3b80d8

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

index af87b3c3832fcde9bc52c24306109ea4a16b440d..b5e7b9a0e6568c071c3c4e1b78ed3ec747449757 100644 (file)
@@ -1068,6 +1068,15 @@ private:
 
     FormatToken *LeftOfParens = Tok.MatchingParen->getPreviousNonComment();
     if (LeftOfParens) {
+      // If there is an opening parenthesis left of the current parentheses,
+      // look past it as these might be chained casts.
+      if (LeftOfParens->is(tok::r_paren)) {
+        if (!LeftOfParens->MatchingParen ||
+            !LeftOfParens->MatchingParen->Previous)
+          return false;
+        LeftOfParens = LeftOfParens->MatchingParen->Previous;
+      }
+
       // If there is an identifier (or with a few exceptions a keyword) right
       // before the parentheses, this is unlikely to be a cast.
       if (LeftOfParens->Tok.getIdentifierInfo() &&
index 02f329acfe559997125b7334bee3e33567e3232e..176c74bf7eef23c444f0ed29c3cfef2f5a2d7454 100644 (file)
@@ -5793,6 +5793,7 @@ TEST_F(FormatTest, FormatsCasts) {
   verifyFormat("int a = sizeof(int *) + b;");
   verifyFormat("int a = alignof(int *) + b;", getGoogleStyle());
   verifyFormat("bool b = f(g<int>) && c;");
+  verifyFormat("typedef void (*f)(int i) func;");
 
   verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *foo = (aaaaaaaaaaaaaaaaa *)\n"
                "    bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");