[llvm-branch-commits] [clang] release/20.x: [clang-format] Fix mismatched break in BlockIndent (#124998) (PR #136238)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Apr 17 18:49:12 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: None (llvmbot)

<details>
<summary>Changes</summary>

Backport b8734797a3f605c4aaa37fcb5007baa273565460

Requested by: @<!-- -->owenca

---
Full diff: https://github.com/llvm/llvm-project/pull/136238.diff


2 Files Affected:

- (modified) clang/lib/Format/ContinuationIndenter.cpp (+7) 
- (modified) clang/unittests/Format/FormatTest.cpp (+4) 


``````````diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index c311deaa17bb0..6f7d213c0b559 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -349,6 +349,13 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
     }
   }
 
+  // Allow breaking before the right parens with block indentation if there was
+  // a break after the left parens, which is tracked by BreakBeforeClosingParen.
+  if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
+      Current.is(tok::r_paren)) {
+    return CurrentState.BreakBeforeClosingParen;
+  }
+
   // Don't allow breaking before a closing brace of a block-indented braced list
   // initializer if there isn't already a break.
   if (Current.is(tok::r_brace) && Current.MatchingParen &&
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 44341fbfe895f..bf3eff129efd5 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9614,6 +9614,10 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
                "        auto aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"
                "    ) {};",
                Style);
+  verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaa(\n"
+               "    &bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n"
+               ");",
+               Style);
 }
 
 TEST_F(FormatTest, ParenthesesAndOperandAlignment) {

``````````

</details>


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


More information about the llvm-branch-commits mailing list