diff options
| author | Daniel Jasper <djasper@google.com> | 2014-08-13 08:46:21 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-08-13 08:46:21 +0000 |
| commit | 839922e9d1ce6d4d0ab94a6a7f2cdc88c2357a7b (patch) | |
| tree | ae46696c6377e851a3d170c321b7b12d532598f5 | |
| parent | 5b1a04426bad9e68e6ab695441582b6067696894 (diff) | |
| download | bcm5719-llvm-839922e9d1ce6d4d0ab94a6a7f2cdc88c2357a7b.tar.gz bcm5719-llvm-839922e9d1ce6d4d0ab94a6a7f2cdc88c2357a7b.zip | |
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
| -rw-r--r-- | clang/lib/Format/FormatToken.cpp | 8 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index c91d25f46de..c6f23a6c281 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 1bd52aa9b5e..cc16c334135 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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. |

