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 /clang/lib/Format | |
| 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
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 12 |
1 files changed, 8 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); |

