[clang] [clang-format] Stop ctor initializer from being inlined (PR #150361)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 23 22:33:06 PDT 2025


================
@@ -7771,6 +7771,37 @@ TEST_F(FormatTest, ConstructorInitializers) {
                "Constructor() :\n"
                "    // Comment forcing unwanted break.\n"
                "    aaaa(aaaa) {}");
+
+  // Braced initializers with trailing commas.
+  verifyFormat("MyClass::MyClass()\n"
+               "    : aaaa{\n"
+               "          0,\n"
+               "      } {}",
+               "MyClass::MyClass():aaaa{0,}{}", getGoogleStyle());
+  verifyFormat("MyClass::MyClass()\n"
+               "    : aaaa(0),\n"
+               "      bbbb{\n"
+               "          0,\n"
+               "      } {}",
+               "MyClass::MyClass():aaaa(0),bbbb{0,}{}", getGoogleStyle());
+  verifyFormat("MyClass::MyClass()\n"
+               "    : aaaa(0),\n"
+               "      bbbb{\n"
+               "          0,\n"
+               "      },\n"
+               "      cccc{\n"
+               "          0,\n"
+               "      } {}",
+               "MyClass::MyClass():aaaa(0),bbbb{0,},cccc{0,}{}",
+               getGoogleStyle());
----------------
owenca wrote:

I would not add these test cases as they can pass without this patch.

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


More information about the cfe-commits mailing list