diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -778,12 +778,11 @@ Changes, /*StartAt=*/0); } else { static auto AlignWrappedOperand = [](Change const &C) { - auto Previous = C.Tok->getPreviousNonComment(); // Previous; + FormatToken *Previous = C.Tok->getPreviousNonComment(); return C.NewlinesBefore && Previous && Previous->is(TT_ConditionalExpr) && - (Previous->is(tok::question) || - (Previous->is(tok::colon) && - (C.Tok->FakeLParens.size() == 0 || - C.Tok->FakeLParens.back() != prec::Conditional))); + (Previous->is(tok::colon) && + (C.Tok->FakeLParens.size() == 0 || + C.Tok->FakeLParens.back() != prec::Conditional)); }; // Ensure we keep alignment of wrapped operands with non-wrapped operands // Since we actually align the operators, the wrapped operands need the diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6459,6 +6459,30 @@ " bbbb ? cccccccccccccccccc :\n" " ddddd;\n", Style); + + EXPECT_EQ( + "MMMMMMMMMMMMMMMMMMMMMMMMMMM = A ?\n" + " /*\n" + " */\n" + " function() {\n" + " try {\n" + " return JJJJJJJJJJJJJJ(\n" + " pppppppppppppppppppppppppppppppppppppppppppppppppp);\n" + " }\n" + " } :\n" + " function() {};", + format( + "MMMMMMMMMMMMMMMMMMMMMMMMMMM = A ?\n" + " /*\n" + " */\n" + " function() {\n" + " try {\n" + " return JJJJJJJJJJJJJJ(\n" + " pppppppppppppppppppppppppppppppppppppppppppppppppp);\n" + " }\n" + " } :\n" + " function() {};", + getGoogleStyle(FormatStyle::LK_JavaScript))); } TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) {