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

Before:
  if () {
  }
    else {
  }

After:
  if () {
  } else {
  }

This fixed llvm.org/PR17262.

llvm-svn: 190855
This commit is contained in:
Daniel Jasper 2013-09-17 08:28:05 +00:00
parent 0de8efa63d
commit 88f9222c4e
2 changed files with 6 additions and 0 deletions

View 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)) {

View 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) {