summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-10-30 14:04:10 +0000
committerDaniel Jasper <djasper@google.com>2013-10-30 14:04:10 +0000
commit16fc75421688428ce6c84cccdaba87c694484045 (patch)
tree76c1c93e89ab5444b218a41cc2fc417344c49a62
parent9885784d67d7154eb5861130cc2b4b29e4cbf9ea (diff)
downloadbcm5719-llvm-16fc75421688428ce6c84cccdaba87c694484045.tar.gz
bcm5719-llvm-16fc75421688428ce6c84cccdaba87c694484045.zip
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
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp3
-rw-r--r--clang/unittests/Format/FormatTest.cpp7
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index c1f448be56b..74cfbf0e901 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -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;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 639b8c89d95..5852d1c0ed4 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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) {
OpenPOWER on IntegriCloud