diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-16 16:23:19 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-16 16:23:19 +0000 |
commit | 8c5fba9f87f39ff18425747fcea2ac9f364e3cfe (patch) | |
tree | da30ad6d25c09f91f66965835e73af40fe32a56b | |
parent | f40f67af436c33a0c76ead87d23f77d186abd8e4 (diff) | |
download | bcm5719-llvm-8c5fba9f87f39ff18425747fcea2ac9f364e3cfe.tar.gz bcm5719-llvm-8c5fba9f87f39ff18425747fcea2ac9f364e3cfe.zip |
Fix parsing error in conditional expressions.
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.
llvm-svn: 172621
-rw-r--r-- | clang/lib/Format/Format.cpp | 7 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 3 |
2 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index ebf493c628a..22166aa27ab 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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(); } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6dd7cad1380..3c92d82f8fb 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) { |