From fef3e209a68a1c28cc9e8d118a022f16e94bc055 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 13 Aug 2014 08:46:21 +0000 Subject: [PATCH] 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: 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 | 8 +++++--- unittests/Format/FormatTest.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Format/FormatToken.cpp b/lib/Format/FormatToken.cpp index c91d25f46d..c6f23a6c28 100644 --- a/lib/Format/FormatToken.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 1bd52aa9b5..cc16c33413 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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. -- 2.40.0