diff options
-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. |