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 @@ -1282,9 +1282,12 @@ C.EscapedNewlineColumn); else appendNewlineText(ReplacementText, C.NewlinesBefore); + // FIXME: This assert should hold if we computed the column correctly. + // assert((int)C.StartOfTokenColumn >= C.Spaces); appendIndentText( ReplacementText, C.Tok->IndentLevel, std::max(0, C.Spaces), - C.StartOfTokenColumn - std::max(0, C.Spaces), C.IsAligned); + std::max((int)C.StartOfTokenColumn, C.Spaces) - std::max(0, C.Spaces), + C.IsAligned); ReplacementText.append(C.CurrentLinePrefix); storeReplacement(C.OriginalWhitespaceRange, ReplacementText); } 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 @@ -13452,6 +13452,25 @@ "}", Tab)); + verifyFormat("void f() {\n" + "\treturn true ? aaaaaaaaaaaaaaaaaa\n" + "\t : bbbbbbbbbbbbbbbbbb\n" + "}", + Tab); + FormatStyle TabNoBreak = Tab; + TabNoBreak.BreakBeforeTernaryOperators = false; + verifyFormat("void f() {\n" + "\treturn true ? aaaaaaaaaaaaaaaaaa :\n" + "\t bbbbbbbbbbbbbbbbbb\n" + "}", + TabNoBreak); + verifyFormat("void f() {\n" + "\treturn true ?\n" + "\t aaaaaaaaaaaaaaaaaaaa :\n" + "\t bbbbbbbbbbbbbbbbbbbb\n" + "}", + TabNoBreak); + Tab.UseTab = FormatStyle::UT_Never; EXPECT_EQ("/*\n" " a\t\tcomment\n"