diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1041,8 +1041,10 @@ // * not remove the 'lead' ContinuationIndentWidth // * always un-indent by the operator when // BreakBeforeTernaryOperators=true - unsigned Indent = - State.Stack.back().Indent - Style.ContinuationIndentWidth; + unsigned Indent = State.Stack.back().Indent; + if (Style.AlignOperands != FormatStyle::OAS_DontAlign) { + Indent -= Style.ContinuationIndentWidth; + } if (Style.BreakBeforeTernaryOperators && State.Stack.back().UnindentOperator) Indent -= 2; 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 @@ -6281,6 +6281,17 @@ " : bbbbbbbbbbbbbbbbbbbbbbb ? 2222222222222222\n" " : 3333333333333333;", Style); + + Style.AlignOperands = FormatStyle::OAS_DontAlign; + Style.BreakBeforeTernaryOperators = false; + // FIXME: Aligning the question marks is weird given DontAlign. + // Consider disabling this alignment in this case. Also check whether this + // will render the adjustment from https://reviews.llvm.org/D82199 + // unnecessary. + verifyFormat("int x = aaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaa :\n" + " bbbb ? cccccccccccccccccc :\n" + " ddddd;\n", + Style); } TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) {