bool PreviousIsBreakingCtorInitializerColon =
PreviousNonComment && PreviousNonComment->is(TT_CtorInitializerColon) &&
Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon;
+ bool AllowAllConstructorInitializersOnNextLine =
+ Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine ||
+ Style.PackConstructorInitializers == FormatStyle::PCIS_NextLineOnly;
if (!(Previous.isOneOf(tok::l_paren, tok::l_brace, TT_BinaryOperator) ||
PreviousIsBreakingCtorInitializerColon) ||
(!Style.AllowAllParametersOfDeclarationOnNextLine &&
State.Line->MustBeDeclaration) ||
(!Style.AllowAllArgumentsOnNextLine &&
!State.Line->MustBeDeclaration) ||
- (Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine &&
+ (!AllowAllConstructorInitializersOnNextLine &&
PreviousIsBreakingCtorInitializerColon) ||
Previous.is(TT_DictLiteral)) {
CurrentState.BreakBeforeParameter = true;
// and we allow all arguments on the next line, we should not break
// before the next parameter.
if (PreviousIsBreakingCtorInitializerColon &&
- Style.PackConstructorInitializers == FormatStyle::PCIS_NextLine) {
+ AllowAllConstructorInitializersOnNextLine) {
CurrentState.BreakBeforeParameter = false;
}
}
if (Style.PackConstructorInitializers > FormatStyle::PCIS_BinPack) {
CurrentState.AvoidBinPacking = true;
CurrentState.BreakBeforeParameter =
- Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine;
+ Style.PackConstructorInitializers != FormatStyle::PCIS_NextLine &&
+ Style.PackConstructorInitializers != FormatStyle::PCIS_NextLineOnly;
} else {
CurrentState.BreakBeforeParameter = false;
}
Style);
verifyFormat("Constructor() : a(a), b(b) {}", Style);
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat("Constructor()\n"
+ " : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
+ Style);
+ verifyFormat("Constructor()\n"
+ " : a(a), b(b) {}",
+ Style);
+ verifyFormat("Constructor()\n"
+ " : aaaaaaaaaaaaaaaaaaaa(a)\n"
+ " , bbbbbbbbbbbbbbbbbbbbb(b)\n"
+ " , cccccccccccccccccccccc(c) {}",
+ Style);
+
Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
verifyFormat("Constructor()\n"
" bbbbbbbbbbbbbbbbbbbbb(b) {}",
Style);
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat("Constructor()\n"
+ " : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
+ Style);
+ verifyFormat("Constructor()\n"
+ " : a(a), b(b) {}",
+ Style);
+ verifyFormat("Constructor()\n"
+ " : aaaaaaaaaaaaaaaaaaaa(a),\n"
+ " bbbbbbbbbbbbbbbbbbbbb(b),\n"
+ " cccccccccccccccccccccc(c) {}",
+ Style);
+
Style.BreakConstructorInitializers = FormatStyle::BCIS_AfterColon;
Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
verifyFormat("Constructor() :\n"
" aaaaaaaaaaaaaaaaaa(a),\n"
" bbbbbbbbbbbbbbbbbbbbb(b) {}",
Style);
+
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat("Constructor() :\n"
+ " aaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
+ Style);
+ verifyFormat("Constructor() :\n"
+ " a(a), b(b) {}",
+ Style);
+ verifyFormat("Constructor() :\n"
+ " aaaaaaaaaaaaaaaaaaaa(a),\n"
+ " bbbbbbbbbbbbbbbbbbbbb(b),\n"
+ " cccccccccccccccccccccc(c) {}",
+ Style);
}
// Test interactions between AllowAllParametersOfDeclarationOnNextLine and
// BreakConstructorInitializers modes
Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
Style.AllowAllParametersOfDeclarationOnNextLine = true;
+ Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
verifyFormat("SomeClassWithALongName::Constructor(\n"
" int aaaaaaaaaaaaaaaaaaaaaaaa, int bbbbbbbbbbbbb)\n"
" : aaaaaaaaaaaaaaaaaaaa(a)\n"
" : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
Style);
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat("SomeClassWithALongName::Constructor(\n"
+ " int aaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " int bbbbbbbbbbbbb,\n"
+ " int cccccccccccccccc)\n"
+ " : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
+ Style);
+
Style.AllowAllParametersOfDeclarationOnNextLine = false;
Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
verifyFormat("SomeClassWithALongName::Constructor(\n"
" : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
Style);
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat("SomeClassWithALongName::Constructor(\n"
+ " int aaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " int bbbbbbbbbbbbb,\n"
+ " int cccccccccccccccc)\n"
+ " : aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
+ Style);
+
Style.AllowAllParametersOfDeclarationOnNextLine = false;
Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
verifyFormat("SomeClassWithALongName::Constructor(\n"
" aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
Style);
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat("SomeClassWithALongName::Constructor(\n"
+ " int aaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " int bbbbbbbbbbbbb,\n"
+ " int cccccccccccccccc) :\n"
+ " aaaaaaaaaaaaaaaaaaaa(a), bbbbbbbbbbbbbbbbbbbbb(b) {}",
+ Style);
+
Style.AllowAllParametersOfDeclarationOnNextLine = false;
Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
verifyFormat("SomeClassWithALongName::Constructor(\n"
" aaaaaaaaaaaaa(aaaaaaaaaaaaaa), aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}",
Style);
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat(
+ "SomeClass::Constructor() :\n"
+ " aaaaaaaaaaaaa(aaaaaaaaaaaaaa), aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}",
+ Style);
+ verifyFormat(
+ "SomeClass::Constructor() : // NOLINT\n"
+ " aaaaaaaaaaaaa(aaaaaaaaaaaaaa), aaaaaaaaaaaaaaa(aaaaaaaaaaaa) {}",
+ Style);
+
Style.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
verifyFormat(
"SomeClass::Constructor() :\n"
input += " a,\n";
input += " a) {}";
verifyFormat(input, OnePerLine);
+ OnePerLine.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat(input, OnePerLine);
}
#endif
"SomeClass::Constructor()\n"
" : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa) {}",
Style);
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat("SomeClass::Constructor()\n"
+ " : aaaaaaaa(aaaaaaaa) {}",
+ Style);
+ verifyFormat("SomeClass::Constructor()\n"
+ " : aaaaa(aaaaa), aaaaa(aaaaa), aaaaa(aaaaa)\n",
+ Style);
+ verifyFormat(
+ "SomeClass::Constructor()\n"
+ " : aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa), aaaaaaaa(aaaaaaaa) {}",
+ Style);
+
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
Style.ConstructorInitializerIndentWidth = 4;
Style.ColumnLimit = 60;
verifyFormat("SomeClass::Constructor()\n"
" , aaaaaaaa(aaaaaaaa)\n"
" , aaaaaaaa(aaaaaaaa) {}",
Style);
+ Style.PackConstructorInitializers = FormatStyle::PCIS_NextLineOnly;
+ verifyFormat("SomeClass::Constructor()\n"
+ " : aaaaaaaa(aaaaaaaa)\n"
+ " , aaaaaaaa(aaaaaaaa)\n"
+ " , aaaaaaaa(aaaaaaaa) {}",
+ Style);
}
TEST_F(FormatTest, ConstructorInitializersWithPreprocessorDirective) {