[clang] [clang-format] Fix OverEmptyLines aligning trailing comments across block boundaries (PR #208324)

via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 27 00:45:07 PDT 2026


================
@@ -3007,6 +3007,130 @@ TEST_F(FormatTestComments, AlignTrailingCommentsAcrossEmptyLines) {
                Style);
 }
 
+TEST_F(FormatTestComments, NonTrailingCommentBreaksAlignment) {
+  // Regression test for https://llvm.org/PR208266
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Proto);
+  Style.AlignConsecutiveAssignments.Enabled = true;
+  Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Always;
+  Style.AlignTrailingComments.OverEmptyLines = 4;
+  Style.ColumnLimit = 0;
+
+  verifyNoChange("enum E {\n"
+                 "  A = 0; /* e */\n"
+                 "}\n"
+                 "/* c */\n"
+                 "message M {\n"
+                 "  int32 a    = 1; /* f */\n"
+                 "  int32 abcd = 2; /* g */\n"
+                 "}",
+                 Style);
----------------
owenca wrote:

> However: If you feel strongly it should be removed, I'll remove.

Yes, please.

We usually don't include the test case from the original bug report unless it's a min repro. (Oftentimes, we don't even include the min repro in FormatTest... if the bug is in the annotation.)

For this bugfix, we just need the following between any two blocks:
- nothing or an empty line
- a comment line
- a line with a trailing comment

which are all covered below.

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


More information about the cfe-commits mailing list