[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 4 19:40:28 PST 2025


================
@@ -11224,6 +11224,328 @@ TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) {
       Style);
 }
 
+TEST_F(FormatTest, BreakBeforeTemplateCloser) {
+  FormatStyle Style = getLLVMStyle();
+  // Begin with tests covering the case where there is no constraint on the
+  // column limit.
+  Style.ColumnLimit = 0;
+  // When BreakBeforeTemplateCloser is turned off, the line break that it adds
+  // shall be removed:
+  verifyFormat("template <\n"
+               "    typename Foo,\n"
+               "    typename Bar>\n"
+               "void foo() {}",
+               "template <\n"
+               "    typename Foo,\n"
+               "    typename Bar\n"
+               ">\n"
+               "void foo() {}",
+               Style);
+
+  Style.BreakBeforeTemplateCloser = true;
+  // BreakBeforeTemplateCloser should NOT force template declarations onto
+  // multiple lines.
+  verifyFormat("template <typename Foo>\n"
+               "void foo() {}",
+               Style);
+  verifyFormat("template <typename Foo, typename Bar>\n"
+               "void foo() {}",
+               Style);
----------------
leijurv wrote:

I apologize, it appears that in my commit https://github.com/leijurv/llvm-project/commit/e1eaba9b05b00adf44628e2ceb1b3374fec902cb I missed removing this one, bit of a coincidence (I swear it wasn't on purpose). I have just now triple checked to ensure that all your other comments were indeed addressed, I believe I only missed this one.

https://github.com/llvm/llvm-project/pull/118046


More information about the cfe-commits mailing list