[clang] [clang-format] Allow line breaking with PointerAlignment configured (PR #164686)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 23 12:57:05 PDT 2025


================
@@ -8644,6 +8644,38 @@ TEST_F(FormatTest, BreaksFunctionDeclarations) {
                "                 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}",
                Style);
 
+  Style.ColumnLimit = 70;
+  verifyFormat(
+      "void foo( //\n"
+      "    const MySuperSuperSuperSuperSuperSuperSuperSuperLongTypeName*\n"
+      "        const my_super_super_super_super_long_variable_name) {}",
+      Style);
+  verifyFormat(
+      "void foo(const MySuperSuperSuperSuperSuperSuperSuperSuperLongTypeName*\n"
+      "             my_super_super_super_super_long_variable_name) {}",
+      Style);
+  verifyFormat(
+      "void foo(const MySuperSuperSuperSuperSuperSuperSuperSuperLongTypeName*\n"
+      "             const my_super_super_super_super_long_variable_name) {}",
+      Style);
+
+  Style.PointerAlignment = FormatStyle::PAS_Middle;
+  verifyFormat(
----------------
HazardyKnusperkeks wrote:

I don't know for whom middle is, but never break between the type and the `*`. And I think #28919 makes a good point, the `const` belongs to the type.
On the other hand violating the column limit, while there is whitespace which can be a line break is also bad. I don't really know. Maybe add a huge penalty on that?
@owenca any opinion?
 

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


More information about the cfe-commits mailing list