diff options
author | Daniel Jasper <djasper@google.com> | 2016-02-03 17:27:10 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2016-02-03 17:27:10 +0000 |
commit | 45860fac374980341e6837f5fd8fd63d34ed3b88 (patch) | |
tree | 7b7cda1761299a9b4447a04676a6008fc4c9f0e6 | |
parent | 169a6374dcab8a88f887fb3dcdaccdd97857c6ca (diff) | |
download | bcm5719-llvm-45860fac374980341e6837f5fd8fd63d34ed3b88.tar.gz bcm5719-llvm-45860fac374980341e6837f5fd8fd63d34ed3b88.zip |
clang-format: Fix formatting of ternary expressions with comments.
Before:
int i = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
/*bbbbbbbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :
ccccccccccccccccccccccccccc;
After:
int i = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?
/*bbbbbbbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :
ccccccccccccccccccccccccccc;
llvm-svn: 259670
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 12 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
2 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index fa51f055438..b65c0e0664c 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -705,11 +705,15 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, if (Current.is(TT_ArraySubscriptLSquare) && State.Stack.back().StartOfArraySubscripts == 0) State.Stack.back().StartOfArraySubscripts = State.Column; - if ((Current.is(tok::question) && Style.BreakBeforeTernaryOperators) || - (Current.getPreviousNonComment() && Current.isNot(tok::colon) && - Current.getPreviousNonComment()->is(tok::question) && - !Style.BreakBeforeTernaryOperators)) + if (Style.BreakBeforeTernaryOperators && Current.is(tok::question)) State.Stack.back().QuestionColumn = State.Column; + if (!Style.BreakBeforeTernaryOperators && Current.isNot(tok::colon)) { + const FormatToken *Previous = Current.Previous; + while (Previous && Previous->isTrailingComment()) + Previous = Previous->Previous; + if (Previous && Previous->is(tok::question)) + State.Stack.back().QuestionColumn = State.Column; + } if (!Current.opensScope() && !Current.closesScope()) State.LowestLevelOnLine = std::min(State.LowestLevelOnLine, Current.NestingLevel); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 6ffeb65280a..e03a484f290 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4694,6 +4694,10 @@ TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { " ccccccccccccccc :\n" " ddddddddddddddd);", Style); + verifyFormat("int i = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ?\n" + " /*bbbbbbbbbbbbbbb=*/bbbbbbbbbbbbbbbbbbbbbbbbb :\n" + " ccccccccccccccccccccccccccc;", + Style); } TEST_F(FormatTest, DeclarationsOfMultipleVariables) { |