@@ -11134,7 +11134,7 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1113411134 "void foo() {}",
1113511135 Style);
1113611136
11137- Style.BreakBeforeTemplateCloser = FormatStyle::BBTCS_Multiline ;
11137+ Style.BreakBeforeTemplateCloser = FormatStyle::BBTCS_BlockIndent ;
1113811138 // BreakBeforeTemplateCloser should NOT force template declarations onto
1113911139 // multiple lines.
1114011140 verifyFormat("template <typename Foo>\n"
@@ -11156,6 +11156,10 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1115611156 ">\n"
1115711157 "void foo() {}",
1115811158 Style);
11159+ verifyNoChange("template <typename Foo,\n"
11160+ " typename Bar>\n"
11161+ "void foo() {}",
11162+ Style);
1115911163 // It should add a line break before > if not already present:
1116011164 verifyFormat("template <\n"
1116111165 " typename Foo\n"
@@ -11285,19 +11289,31 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1128511289 ">\n"
1128611290 "void foo() {}",
1128711291 Style);
11288- // But not when the name is looong:
11292+ // But not when the name is looong. Note that these names are exactly 1
11293+ // character too long for the ColumnLimit.
1128911294 verifyFormat("template <\n"
1129011295 " typename Foo,\n"
11291- " typename Barrrrrrrrrrrrrrrrrrrrrrrrrr \n"
11296+ " typename Barrrrrrrrrrrrrrrrrrrr \n"
1129211297 ">\n"
1129311298 "void foo() {}",
1129411299 Style);
11300+ // Note that this "Foo" is 1 character shorter than the previous "Bar" because
11301+ // of the comma.
1129511302 verifyFormat("template <\n"
11296- " typename Fooooooooooooooooooooooooooo ,\n"
11303+ " typename Foooooooooooooooooooo ,\n"
1129711304 " typename Bar\n"
1129811305 ">\n"
1129911306 "void foo() {}",
1130011307 Style);
11308+ // BlockIndent style is used when the ColumnLimit allows it:
11309+ verifyFormat("template <typename Foo,\n"
11310+ " typename Barrrrrrrrrrrrrrrrrr>\n"
11311+ "void foo() {}",
11312+ Style);
11313+ verifyFormat("template <typename Fooooooooooooooooooo,\n"
11314+ " typename Bar>\n"
11315+ "void foo() {}",
11316+ Style);
1130111317 // Additionally, long names should be split in one step:
1130211318 verifyFormat(
1130311319 "template <\n"
@@ -11346,17 +11362,32 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1134611362 " []<typename T,\n"
1134711363 " typename Loooooooooooooooooooooooooooooooooong\n"
1134811364 " >(T t) {};\n"
11365+ // Because this is not BlockIndent style, and the [] is empty,
11366+ // and the "T" is short, then the ">" is placed on the same line.
11367+ " auto lambda =\n"
11368+ " []<typename Loooooooooooooooooooooooooooooooooong,\n"
11369+ " typename T>(T t) {};\n"
1134911370 // Nested:
1135011371 " auto lambda =\n"
1135111372 " []<template <typename, typename>\n"
1135211373 " typename Looooooooooooooooooong\n"
1135311374 " >(T t) {};\n"
11354- // Nested with long capture:
11375+ // Same idea, the "T" is now short rather than Looong:
11376+ " auto lambda =\n"
11377+ " []<template <typename, typename>\n"
11378+ " typename T>(T t) {};\n"
11379+ // Nested with long capture forces the style to block indent:
1135511380 " auto lambda =\n"
1135611381 " [loooooooooooooooooooong]<\n"
1135711382 " template <typename, typename>\n"
1135811383 " typename Looooooooooooooooooong\n"
1135911384 " >(T t) {};\n"
11385+ // But *now* it stays block indented even when T is short:
11386+ " auto lambda =\n"
11387+ " [loooooooooooooooooooong]<\n"
11388+ " template <typename, typename>\n"
11389+ " typename T\n"
11390+ " >(T t) {};\n"
1136011391 // Nested, with long name and long captures:
1136111392 " auto lambda =\n"
1136211393 " [loooooooooooooooooooong]<\n"
@@ -11366,6 +11397,13 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1136611397 " >\n"
1136711398 " typename T\n"
1136811399 " >(T t) {};\n"
11400+ // Allow the nested template to be on the same line:
11401+ " auto lambda =\n"
11402+ " [loooooooooooooooooooong]<\n"
11403+ " template <typename Fooooooooo,\n"
11404+ " typename>\n"
11405+ " typename T\n"
11406+ " >(T t) {};\n"
1136911407 "}",
1137011408 Style);
1137111409 // Test that if the type is NOT long, it pulls it back into one line:
@@ -11387,6 +11425,12 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1138711425 " >();\n"
1138811426 "}",
1138911427 Style);
11428+ // But if the type is short, we don't need block indent style:
11429+ verifyFormat("void foo() {\n"
11430+ " myFunc<Foo, Foo, Foo, Foo, Foo, Foo,\n"
11431+ " Foo, Foo>();\n"
11432+ "}",
11433+ Style);
1139011434}
1139111435
1139211436TEST_F(FormatTest, WrapsTemplateParameters) {
0 commit comments