diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ee9172227b02..58a1eeb5a6d0 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1061,6 +1061,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) { Style.BreakConstructorInitializersBeforeComma) { Current->MustBreakBefore = true; } else if (Current->Previous->BlockKind == BK_Block && + Current->Previous->isNot(tok::r_brace) && Current->isNot(tok::r_brace)) { Current->MustBreakBefore = true; } else if (Current->is(tok::l_brace) && (Current->BlockKind == BK_Block)) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 2dfc4059e666..3c295259c8fa 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -351,6 +351,11 @@ TEST_F(FormatTest, ParseIfElse) { "else {\n" " i();\n" "}"); + verifyFormat("void f() {\n" + " if (a) {\n" + " } else {\n" + " }\n" + "}"); } TEST_F(FormatTest, ElseIf) {