[clang] [clang-format] Propagate `LeadingEmptyLinesAffected` when joining lines (PR #146761)

Eric Li via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 5 00:51:49 PDT 2025


================
@@ -986,7 +986,7 @@ class LineJoiner {
   void join(AnnotatedLine &A, const AnnotatedLine &B) {
     assert(!A.Last->Next);
     assert(!B.First->Previous);
-    if (B.Affected)
+    if (B.Affected || (B.LeadingEmptyLinesAffected && A.Last->Children.empty()))
----------------
tJener wrote:

I suppose it depends. It's unclear to me what the contract of `join` is supposed to be. If it is supposed to merge two arbitrary `AnnotatedLine`s, then it seems like we should keep the check for `Children.empty()` in order to be consistent with `AffectedRangeManager`. If instead one of the preconditions for `join` is that `A.Last->Children.empty()`, then I'd rather assert on that instead of only dropping the condition on the `if`.

That said, I'm just trying to fix a bug that's blocking progress on other stuff, so I'll just do whatever you want me to do here.

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


More information about the cfe-commits mailing list