clang-format: Fix behavior with comments before conditional expressions

Before:
  SomeFunction(aaaaaaaaaaaaaaaaa,
               // comment.
                   ccccccccccccccccc ? aaaaaaaaaaaaaaaaaaaa
                                     : bbbbbbbbbbbbbbbbbbbb);

After:
  SomeFunction(aaaaaaaaaaaaaaaaa,
               // comment.
               ccccccccccccccccc ? aaaaaaaaaaaaaaaaaaaa : bbbbbbbbbbbbbbbbbbbb);

llvm-svn: 219921
This commit is contained in:
Daniel Jasper 2014-10-16 09:10:11 +00:00
parent 823d8f6246
commit 1a31bab301
2 changed files with 9 additions and 0 deletions

View File

@ -1174,6 +1174,9 @@ private:
}
void parseConditionalExpr() {
while (Current && Current->isTrailingComment()) {
next();
}
FormatToken *Start = Current;
parse(prec::LogicalOr);
if (!Current || !Current->is(tok::question))

View File

@ -4060,6 +4060,12 @@ TEST_F(FormatTest, BreaksConditionalExpressions) {
" ?: aaaaaaaaaaaaaaa);\n"
"}",
NoBinPacking);
verifyFormat("SomeFunction(aaaaaaaaaaaaaaaaa,\n"
" // comment.\n"
" ccccccccccccccccccccccccccccccccccccccc\n"
" ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
" : bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);");
}
TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) {