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

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 23 06:07:21 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(
----------------
sstwcw wrote:

I looked into it.  Now I can't figure out whether the formatter should break the line between the type and the star when middle is configured.  I thought that the default right style was for people who read "the expression `*x` is of type `int`", while the left and middle styles were for people who read "the variable `x` is of type `int*`".  Then it seems that the program should avoid breaking between the type and the star when the style is left or middle.  However, the code says that the program should not break the line between the star and const when right is selected (pull request #128817, bug report #28919).  That seems to contradict my understanding about the styles.  What is the reasoning behind the pull request?

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


More information about the cfe-commits mailing list