clang-format: Format long lists in columns if without bin-packing.

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.

llvm-svn: 215529
This commit is contained in:
Daniel Jasper 2014-08-13 08:46:21 +00:00
parent 5b1a04426b
commit 839922e9d1
2 changed files with 12 additions and 3 deletions

View 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;

View 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.