r193684 - clang-format: Fix indenting corner case with comment and else.
Daniel Jasper
djasper at google.com
Wed Oct 30 07:04:10 PDT 2013
Author: djasper
Date: Wed Oct 30 09:04:10 2013
New Revision: 193684
URL: http://llvm.org/viewvc/llvm-project?rev=193684&view=rev
Log:
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();
}
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=193684&r1=193683&r2=193684&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Oct 30 09:04:10 2013
@@ -391,7 +391,8 @@ unsigned ContinuationIndenter::addTokenO
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;
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=193684&r1=193683&r2=193684&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Oct 30 09:04:10 2013
@@ -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) {
More information about the cfe-commits
mailing list