]> granicus.if.org Git - clang/commitdiff
clang-format: Fix bug in column layout.
authorDaniel Jasper <djasper@google.com>
Tue, 27 Aug 2013 08:43:47 +0000 (08:43 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 27 Aug 2013 08:43:47 +0000 (08:43 +0000)
Before (with 60 character limit in Google style):
  return {
      {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa},
      {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}};
After:
  return {{aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa},
          {aaaaaaaaaaaaaaaaaaaaaaaaa}, {aaaaaaaaaaaaaaaaa}};

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

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

index 24a296adc2404a723ff3d09a66deb8611567fe2d..e6c72ab0de9b8ff89edd4becc9fa834cf54328be 100644 (file)
@@ -39,9 +39,13 @@ unsigned CommaSeparatedList::format(LineState &State,
       LBrace->Next->Type == TT_DesignatedInitializerPeriod)
     return 0;
 
+  // Calculate the number of code points we have to format this list. As the
+  // first token is already placed, we have to subtract it.
+  unsigned RemainingCodePoints = Style.ColumnLimit - State.Column +
+                                 State.NextToken->Previous->CodePointCount;
+
   // Find the best ColumnFormat, i.e. the best number of columns to use.
-  unsigned RemainingCharacters = Style.ColumnLimit - State.Stack.back().Indent;
-  const ColumnFormat *Format = getColumnFormat(RemainingCharacters);
+  const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
   if (!Format)
     return 0;
 
index fed054d0aea79631d3f10853a6ccf96b2795af9a..19a764cc6c5a08aba8bcb260a19225e11c054dc0 100644 (file)
@@ -4195,6 +4195,9 @@ TEST_F(FormatTest, FormatsBracedListsinColumnLayout) {
                "                  1, 1, 1, 1,\n"
                "                  /**/ /**/ };",
                getLLVMStyleWithColumns(39));
+  verifyFormat("return { { aaaaaaaaaaaaaaaaaaaaa }, { aaaaaaaaaaaaaaaaaaa },\n"
+               "         { aaaaaaaaaaaaaaaaaaaaa }, { aaaaaaaaaaaaaaaaa } };",
+               getLLVMStyleWithColumns(60));
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {