Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 343f33f

Browse files
committed
clang-format: Respect BinPackParameters in Cpp11BracedListStyle.
With BinPackParameters=false and Cpp11BracedListStyle=true (i.e. mostly for Chromium): Before: const Aaaaaa aaaaa = {aaaaa, bbbbb, ccccc, ddddd, eeeee, ffffff, ggggg, hhhhhh, iiiiii, jjjjjj, kkkkkk}; After: const Aaaaaa aaaaa = {aaaaa, bbbbb, ccccc, ddddd, eeeee, ffffff, ggggg, hhhhhh, iiiiii, jjjjjj, kkkkkk}; This fixes llvm.org/PR19359. I am not sure we'll want this in all cases in the long run, but I'll guess we'll get feedback on that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206458 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 594e55b commit 343f33f

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Diff for: lib/Format/ContinuationIndenter.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
725725
AvoidBinPacking = Current.BlockKind == BK_Block ||
726726
Current.Type == TT_ArrayInitializerLSquare ||
727727
Current.Type == TT_DictLiteral ||
728+
!Style.BinPackParameters ||
728729
(NextNoComment &&
729730
NextNoComment->Type == TT_DesignatedInitializerPeriod);
730731
} else {

Diff for: lib/Format/FormatToken.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
132132
if (!Token->MatchingParen || Token->isNot(tok::l_brace))
133133
return;
134134

135+
// In C++11 braced list style, we should not format in columns unless we allow
136+
// bin-packing of function parameters.
137+
if (Style.Cpp11BracedListStyle && !Style.BinPackParameters)
138+
return;
139+
135140
FormatToken *ItemBegin = Token->Next;
136141
SmallVector<bool, 8> MustBreakBeforeItem;
137142

Diff for: unittests/Format/FormatTest.cpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -5027,7 +5027,7 @@ TEST_F(FormatTest, LayoutBraceInitializersInReturnStatement) {
50275027
verifyFormat("return (a)(b) {1, 2, 3};");
50285028
}
50295029

5030-
TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
5030+
TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
50315031
verifyFormat("vector<int> x{1, 2, 3, 4};");
50325032
verifyFormat("vector<int> x{\n"
50335033
" 1, 2, 3, 4,\n"
@@ -5049,6 +5049,36 @@ TEST_F(FormatTest, LayoutCxx11ConstructorBraceInitializers) {
50495049
"};");
50505050
verifyFormat("vector<int> foo = {::SomeGlobalFunction()};");
50515051

5052+
// In combination with BinPackParameters = false.
5053+
FormatStyle NoBinPacking = getLLVMStyle();
5054+
NoBinPacking.BinPackParameters = false;
5055+
verifyFormat("const Aaaaaa aaaaa = {aaaaa,\n"
5056+
" bbbbb,\n"
5057+
" ccccc,\n"
5058+
" ddddd,\n"
5059+
" eeeee,\n"
5060+
" ffffff,\n"
5061+
" ggggg,\n"
5062+
" hhhhhh,\n"
5063+
" iiiiii,\n"
5064+
" jjjjjj,\n"
5065+
" kkkkkk};",
5066+
NoBinPacking);
5067+
verifyFormat("const Aaaaaa aaaaa = {\n"
5068+
" aaaaa,\n"
5069+
" bbbbb,\n"
5070+
" ccccc,\n"
5071+
" ddddd,\n"
5072+
" eeeee,\n"
5073+
" ffffff,\n"
5074+
" ggggg,\n"
5075+
" hhhhhh,\n"
5076+
" iiiiii,\n"
5077+
" jjjjjj,\n"
5078+
" kkkkkk,\n"
5079+
"};",
5080+
NoBinPacking);
5081+
50525082
// FIXME: The alignment of these trailing comments might be bad. Then again,
50535083
// this might be utterly useless in real code.
50545084
verifyFormat("Constructor::Constructor()\n"

0 commit comments

Comments
 (0)