]> granicus.if.org Git - clang/commitdiff
clang-format: Fix line breaking bug after empty ifs.
authorDaniel Jasper <djasper@google.com>
Tue, 17 Sep 2013 08:28:05 +0000 (08:28 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 17 Sep 2013 08:28:05 +0000 (08:28 +0000)
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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index ee9172227b0212ef81e99e28ccb3d809b13359f2..58a1eeb5a6d0957fd90bb4f38d3ea780da10e047 100644 (file)
@@ -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)) {
index 2dfc4059e6665371899fb852f817a6fbb7109e06..3c295259c8fa1196e545053290d4b288306da486 100644 (file)
@@ -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) {