| Issue |
208266
|
| Summary |
[clang-format] AlignTrailingComments with OverEmptyLines misaligns previously stable file after #206393
|
| Labels |
clang-format
|
| Assignees |
|
| Reporter |
earnol
|
After bae9ddca423145baf0c35e31898b723aa273f85c (#206393), a previously stable file gets reformatted, because a trailing comment in an enum is shifted to align with trailing comments in a subsequent message block, even though they are separated by a non-trailing block comment.
**Configuration (.clang-format):**
```
---
Language: Proto
BasedOnStyle: Google
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignTrailingComments:
Kind: Always
OverEmptyLines: 4
ColumnLimit: 0
```
**Input (stable before bae9ddca4231, unstable after)**:
```
enum E {
OK = 0; /* Operation completed successfully. */
}
/* comment */
message M {
optional uint32 field_a = 1; /* Short description of field_a */
repeated uint32 field_b_long_name_for_align = 2; /* Multi-line
description */
}
```
**Expected behavior**:
No change — the file is already correctly formatted.
**Actual**:
The trailing comment in the enum is shifted to align with the trailing comments in the message below, despite a non-trailing /* comment */ block separating them.
**Analysis**:
The new condition added in WhitespaceManager::calculateLineBreakInformation():
```
(P.NewlinesBefore == 0 || !PP || PP->IsTrailingComment)
```
changes how IsTrailingComment propagates. The non-trailing block comment (/* comment */ on its own line) is now incorrectly treated in a way that allows the AlignTrailingComments logic with OverEmptyLines: 4 to "see through" it and align comments across unrelated blocks.
Before the patch, the block comment acted as a barrier preventing cross-block trailing comment alignment. After the patch, it no longer does.
**Verified**:
Reverting bae9ddca4231 on current HEAD restores idempotency.
Simplification done with: kiro-cli.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs