aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-16 16:23:19 +0000
committerDaniel Jasper <djasper@google.com>2013-01-16 16:23:19 +0000
commit1f2b07898f66524fd7fe1b177fb0d7c58016e93b (patch)
tree61a037369b9ba374ee0dd631f6b8d1847ffd8b13
parent7f69b1ab4f63ded511dddd7fb7e1cd8860757016 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172621 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/Format.cpp7
-rw-r--r--unittests/Format/FormatTest.cpp3
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index ebf493c628..22166aa27a 100644
--- a/lib/Format/Format.cpp
+++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 6dd7cad138..3c92d82f8f 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/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) {