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();
}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193684 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp
index c1f448b..74cfbf0 100644
--- a/lib/Format/ContinuationIndenter.cpp
+++ b/lib/Format/ContinuationIndenter.cpp
@@ -391,7 +391,8 @@
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;
}
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 639b8c8..5852d1c 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -374,6 +374,13 @@
" g();\n"
"else\n"
" h();");
+ verifyFormat("if (a) {\n"
+ " f();\n"
+ "}\n"
+ "// or else ..\n"
+ "else {\n"
+ " g()\n"
+ "}");
}
TEST_F(FormatTest, FormatsForLoop) {