[clang] [clang-format] Fixing erroneous trailing comma (PR #205631)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 24 11:49:04 PDT 2026


================
@@ -270,6 +270,12 @@ llvm::Error Replacements::add(const Replacement &R) {
     assert(R.getLength() == 0);
     // `I` is also an insertion, `R` and `I` conflict.
     if (I->getLength() == 0) {
+      // If the two insertions are identical, `R` is redundant; keep the
+      // existing one rather than concatenating. This happens e.g. when
+      // clang-format analyzes the same code under several preprocessor
+      // branches and emits the same insertion in each run.
+      if (R.getReplacementText() == I->getReplacementText())
----------------
HazardyKnusperkeks wrote:

This fixes the symptom, while the root cause is kept. I'm currently not that fit in the preprocessor branches stuff, but it would be nice if we can fix it there. It it outside of the branches and an unwrapped line on itself.

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


More information about the cfe-commits mailing list