r190855 - clang-format: Fix line breaking bug after empty ifs.

Daniel Jasper djasper at google.com
Tue Sep 17 01:28:05 PDT 2013


Author: djasper
Date: Tue Sep 17 03:28:05 2013
New Revision: 190855

URL: http://llvm.org/viewvc/llvm-project?rev=190855&view=rev
Log:
clang-format: Fix line breaking bug after empty ifs.

Before:
  if () {
  }
    else {
  }

After:
  if () {
  } else {
  }

This fixed llvm.org/PR17262.

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=190855&r1=190854&r2=190855&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Sep 17 03:28:05 2013
@@ -1061,6 +1061,7 @@ void TokenAnnotator::calculateFormatting
                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)) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=190855&r1=190854&r2=190855&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Sep 17 03:28:05 2013
@@ -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) {





More information about the cfe-commits mailing list