diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index a8e2c5556a83540397a61e0b2f6b48b1480791ca..c83ec604758ee99c66d323f2154d3d44ceedd746 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1174,6 +1174,9 @@ private: } void parseConditionalExpr() { + while (Current && Current->isTrailingComment()) { + next(); + } FormatToken *Start = Current; parse(prec::LogicalOr); if (!Current || !Current->is(tok::question)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b195df4291c16acc5e1a0976badbed7e5cdfc80d..aebfef6fbea7c398cc2b2a09179c8b65da167292 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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) {