From: Daniel Jasper Date: Tue, 17 Sep 2013 08:28:05 +0000 (+0000) Subject: clang-format: Fix line breaking bug after empty ifs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e63a48a21cb3416edc6bc75d4d24f3bcf23532d4;p=clang clang-format: Fix line breaking bug after empty ifs. Before: if () { } else { } After: if () { } else { } This fixed llvm.org/PR17262. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190855 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ee9172227b..58a1eeb5a6 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 2dfc4059e6..3c295259c8 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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) {