clang-format: Fix indenting corner case with comment and else.

Before:
  if (a) {
    f();
  }
      // or else ..
      else {
    g();
  }

After:
  if (a) {
    f();
  }
  // or else ..
  else {
    g();
  }

llvm-svn: 193684
This commit is contained in:
Daniel Jasper 2013-10-30 14:04:10 +00:00
parent 9885784d67
commit 16fc754216
2 changed files with 9 additions and 1 deletions

View File

@ -391,7 +391,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
State.Column = State.Stack.back().Indent;
// Ensure that we fall back to the continuation indent width instead of just
// flushing continuations left.
if (State.Column == State.FirstIndent)
if (State.Column == State.FirstIndent &&
PreviousNonComment->isNot(tok::r_brace))
State.Column += Style.ContinuationIndentWidth;
}

View File

@ -374,6 +374,13 @@ TEST_F(FormatTest, ElseIf) {
" g();\n"
"else\n"
" h();");
verifyFormat("if (a) {\n"
" f();\n"
"}\n"
"// or else ..\n"
"else {\n"
" g()\n"
"}");
}
TEST_F(FormatTest, FormatsForLoop) {