]> granicus.if.org Git - clang/commitdiff
clang-format: Fix regression introduced by r190038.
authorDaniel Jasper <djasper@google.com>
Fri, 6 Sep 2013 21:46:41 +0000 (21:46 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 6 Sep 2013 21:46:41 +0000 (21:46 +0000)
Before:
  Constructor()
      : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) {
                                 }
After:
  Constructor()
      : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) {
  }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190209 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 12cfd48f5b38dfaf3bc9965eac13861743a905b8..40d9d2f7d292ff17daab973ba983f5191f5bbe6b 100644 (file)
@@ -225,7 +225,12 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
       Penalty += Style.PenaltyBreakFirstLessLess;
 
     if (Current.is(tok::r_brace)) {
-      State.Column = State.Stack[State.Stack.size() - 2].LastSpace;
+      if (Current.MatchingParen &&
+          (Current.MatchingParen->BlockKind == BK_BracedInit ||
+           !Current.MatchingParen->Children.empty()))
+        State.Column = State.Stack[State.Stack.size() - 2].LastSpace;
+      else
+        State.Column = State.FirstIndent;
     } else if (Current.is(tok::string_literal) &&
                State.StartOfStringLiteral != 0) {
       State.Column = State.StartOfStringLiteral;
index 79dbad79c67cb1f728974d35020c9bf80fc0f72c..10a6316054b0cbed2b26459400a62346eb4a7650 100644 (file)
@@ -2495,6 +2495,10 @@ TEST_F(FormatTest, ConstructorInitializers) {
   verifyFormat("Constructor(int Parameter = 0)\n"
                "    : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaa),\n"
                "      aaaaaaaaaaaa(aaaaaaaaaaaaaaaaa) {}");
+  verifyFormat("Constructor()\n"
+               "    : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbbbbb(b) {\n"
+               "}",
+               getLLVMStyleWithColumns(60));
 
   // Here a line could be saved by splitting the second initializer onto two
   // lines, but that is not desireable.