]> granicus.if.org Git - clang/commitdiff
clang-format: Format long lists in columns if without bin-packing.
authorDaniel Jasper <djasper@google.com>
Wed, 13 Aug 2014 08:46:21 +0000 (08:46 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 13 Aug 2014 08:46:21 +0000 (08:46 +0000)
After (even with BinPacking = false):
  const Aaaaaa aaaaa = {
      aaaaa,  bbbbb,  ccccc,  ddddd,  eeeee,  ffffff, ggggg, hhhhhh,
      iiiiii, jjjjjj, kkkkkk, aaaaa,  bbbbb,  ccccc,  ddddd, eeeee,
      ffffff, ggggg,  hhhhhh, iiiiii, jjjjjj, kkkkkk,
  };

Before:
  <each element on its own line>

This fixes http://llvm.org/PR20623.

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

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

index c91d25f46de1f5263a03a8ae77044b06f2c68209..c6f23a6c281b5491e2f2a0152504aba690589099 100644 (file)
@@ -131,9 +131,11 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
   if (!Token->MatchingParen || Token->isNot(tok::l_brace))
     return;
 
-  // In C++11 braced list style, we should not format in columns unless we allow
-  // bin-packing of function parameters.
-  if (Style.Cpp11BracedListStyle && !Style.BinPackParameters)
+  // In C++11 braced list style, we should not format in columns unless they
+  // have many items (20 or more) or we allow bin-packing of function
+  // parameters.
+  if (Style.Cpp11BracedListStyle && !Style.BinPackParameters &&
+      Commas.size() < 19)
     return;
 
   FormatToken *ItemBegin = Token->Next;
index 1bd52aa9b5eccdadba8f6a5e82be990a7b989b85..cc16c334135048ba2f79c4e4f8bfb93d6554b838 100644 (file)
@@ -5441,6 +5441,13 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
                "    kkkkkk,\n"
                "};",
                NoBinPacking);
+  verifyFormat(
+      "const Aaaaaa aaaaa = {\n"
+      "    aaaaa,  bbbbb,  ccccc,  ddddd,  eeeee,  ffffff, ggggg, hhhhhh,\n"
+      "    iiiiii, jjjjjj, kkkkkk, aaaaa,  bbbbb,  ccccc,  ddddd, eeeee,\n"
+      "    ffffff, ggggg,  hhhhhh, iiiiii, jjjjjj, kkkkkk,\n"
+      "};",
+      NoBinPacking);
 
   // FIXME: The alignment of these trailing comments might be bad. Then again,
   // this might be utterly useless in real code.