]> granicus.if.org Git - clang/commitdiff
Fix parsing error in conditional expressions.
authorDaniel Jasper <djasper@google.com>
Wed, 16 Jan 2013 16:23:19 +0000 (16:23 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 16 Jan 2013 16:23:19 +0000 (16:23 +0000)
We used to incorrectly parse

aaaaaa ? aaaaaa(aaaaaa) : aaaaaaaa;

Due to an l_paren being followed by a colon, we assumed it to be part of
a constructor initializer. Thus, we never found the colon belonging to
the conditional expression, marked the line as bing incorrect and did
not format it.

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

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

index ebf493c628a328d00732325effa40e80a9d0e890..22166aa27ab1b45409d92d62117601b1bee09d8b 100644 (file)
@@ -886,6 +886,8 @@ public:
         break;
       case tok::colon:
         // Colons from ?: are handled in parseConditional().
+        if (Tok->Parent->is(tok::r_paren))
+          Tok->Type = TT_CtorInitializerColon;
         if (ColonIsObjCMethodExpr)
           Tok->Type = TT_ObjCMethodExpr;
         break;
@@ -894,10 +896,7 @@ public:
                                         TT_ObjCMethodSpecifier;
         if (!parseParens())
           return false;
-        if (CurrentToken != NULL && CurrentToken->is(tok::colon)) {
-          CurrentToken->Type = TT_CtorInitializerColon;
-          next();
-        } else if (CurrentToken != NULL && ParensWereObjCReturnType) {
+        if (CurrentToken != NULL && ParensWereObjCReturnType) {
           CurrentToken->Type = TT_ObjCSelectorStart;
           next();
         }
index 6dd7cad13800ff100515f800902d26822b7f6de8..3c92d82f8fb528f17c8478ec56700d98df902eeb 100644 (file)
@@ -917,6 +917,9 @@ TEST_F(FormatTest, BreaksConditionalExpressions) {
       "         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
   verifyFormat("aaaa(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa ?\n"
                "         aaaaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaaa);");
+  verifyFormat(
+      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaa ? aaaa(aaaaaa) :\n"
+      "                                   aaaaaaaaaaaaa);");
 }
 
 TEST_F(FormatTest, ConditionalExpressionsInBrackets) {