]> granicus.if.org Git - clang/commitdiff
clang-format: Fix indenting corner case with comment and else.
authorDaniel Jasper <djasper@google.com>
Wed, 30 Oct 2013 14:04:10 +0000 (14:04 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 30 Oct 2013 14:04:10 +0000 (14:04 +0000)
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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index c1f448be56b0895a52807da7df52b74be34e71f9..74cfbf0e901932a1f7b8f606bd1ffe24e7fd78fe 100644 (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;
   }
 
index 639b8c89d9566c2c4092eefb95733814077da795..5852d1c0ed415ae216a56e51af98ac67931887cb 100644 (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) {