[clang] Add support for aligning BlockComments in declarations (PR #109497)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 20 17:02:23 PST 2024


================
@@ -20029,6 +20029,52 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
                Alignment);
 }
 
+TEST_F(FormatTest, AlignConsecutiveDeclarationsBlockComments) {
+  FormatStyle Style = getLLVMStyleWithColumns(80);
+  Style.AlignConsecutiveDeclarations.Enabled = true;
+  Style.AlignConsecutiveDeclarations.AlignBlockComments = true;
+  Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+  Style.BinPackArguments = false;
+
+  verifyFormat(
+      "bool SomeLongMethodName(int                longParameterNameA,\n"
+      "                        bool               /*longParameterNameB*/,\n"
+      "                        const std::string &longParameterNameC);",
+      "bool SomeLongMethodName(int longParameterNameA,\n"
+      "                        bool /*longParameterNameB*/,\n"
+      "                        const std::string &longParameterNameC);",
+      Style);
+
+  verifyFormat(
+      "const bool ret = SomeLongMethodName(4    /*parameterNameA*/,\n"
+      "                                    true /*longParameterNameB*/,\n"
+      "                                    str  /*longestParameterNameC*/);",
----------------
JessehMSFT wrote:

Thanks @owenca , did you have a suggestion? I thought mostly the argument alignment would follow the declaration parameter alignment for consistency.

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


More information about the cfe-commits mailing list