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 @@ -727,8 +727,10 @@ Style.Cpp11BracedListStyle)) && State.Column > getNewLineColumn(State) && (!Previous.Previous || - !Previous.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while, - tok::kw_switch)) && + !(Previous.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while, + tok::kw_switch) || + (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent && + Previous.Previous->isIf()))) && // Don't do this for simple (no expressions) one-argument function calls // as that feels like needlessly wasting whitespace, e.g.: // 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 @@ -25501,6 +25501,38 @@ " return;\n" "}", Style); + + verifyFormat("void foo() {\n" + " if (quitelongname < alsolongname ||\n" + " anotherevenlongername <=\n" + " thisreallyreallyreallyreallyreallyreallylongername ||" + "\n" + " othername < thislastname) {\n" + " return;\n" + " } else if (quitelongname < alsolongname ||\n" + " anotherevenlongername <=\n" + " thisreallyreallyreallyreallyreallyreallylonger" + "name ||\n" + " othername < thislastname) {\n" + " return;\n" + " }\n" + "}", + Style); + + Style.ContinuationIndentWidth = 2; + verifyFormat("void foo() {\n" + " if (ThisIsRatherALongIfClause && thatIExpectToBeBroken ||\n" + " ontoMultipleLines && whenFormattedCorrectly) {\n" + " if (false) {\n" + " return;\n" + " } else if (thisIsRatherALongIfClause && " + "thatIExpectToBeBroken ||\n" + " ontoMultipleLines && whenFormattedCorrectly) {\n" + " return;\n" + " }\n" + " }\n" + "}", + Style); } TEST_F(FormatTest, AlignAfterOpenBracketBlockIndentForStatement) {