]> granicus.if.org Git - clang/commitdiff
Fix bug in formatting of nested initializers.
authorDaniel Jasper <djasper@google.com>
Sun, 3 Feb 2013 18:07:15 +0000 (18:07 +0000)
committerDaniel Jasper <djasper@google.com>
Sun, 3 Feb 2013 18:07:15 +0000 (18:07 +0000)
We can now format:
SomeArrayOfSomeType a = { { { 1, 2, 3 } }, { { 1, 2, 3 } },
                          { { 111111111111111111111111111111,
                              222222222222222222222222222222,
                              333333333333333333333333333333 } },
                          { { 1, 2, 3 } }, { { 1, 2, 3 } } };

Before, we did strange things there.

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

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

index d638221de636d0d2ef6d7d90bf0b588ab724a502..6cfa0d88239a80e508cc026e7586022360a70e4e 100644 (file)
@@ -528,7 +528,6 @@ private:
     if (Current.is(tok::question))
       State.Stack.back().QuestionColumn = State.Column;
     if (Current.is(tok::l_brace) && Current.MatchingParen != NULL &&
-        Current.Children[0].isNot(tok::l_brace) &&
         !Current.MatchingParen->MustBreakBefore) {
       AnnotatedToken *End = Current.MatchingParen;
       while (!End->Children.empty() && !End->Children[0].CanBreakBefore) {
index bffbbf53316b5f56d83eebddad28baa287bc2fe8..ef97df951ab0ead6dc82398780f0a3e196794667 100644 (file)
@@ -693,6 +693,12 @@ TEST_F(FormatTest, NestedStaticInitializers) {
       "                              222222222222222222222222222222,\n"
       "                              333333333333333333333333333333 },\n"
       "                            { 1, 2, 3 }, { 1, 2, 3 } } };");
+  verifyFormat(
+      "SomeArrayOfSomeType a = { { { 1, 2, 3 } }, { { 1, 2, 3 } },\n"
+      "                          { { 111111111111111111111111111111,\n"
+      "                              222222222222222222222222222222,\n"
+      "                              333333333333333333333333333333 } },\n"
+      "                          { { 1, 2, 3 } }, { { 1, 2, 3 } } };");
 
   // FIXME: We might at some point want to handle this similar to parameter
   // lists, where we have an option to put each on a single line.