https://github.com/johnnyb2543 updated 
https://github.com/llvm/llvm-project/pull/215039

>From 26033199315913048b7323b5a532966cb68a55f9 Mon Sep 17 00:00:00 2001
From: John Boncore <[email protected]>
Date: Sat, 8 Aug 2026 19:56:16 -0400
Subject: [PATCH] [clang-format] Fix BreakAfterOpenBracketIf with unary
 operators

---
 clang/lib/Format/ContinuationIndenter.cpp | 11 ++++++-----
 clang/unittests/Format/FormatTest.cpp     | 24 +++++++++++++++++++++--
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 085b48fd1ed78..ce4d75e69b3b7 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -964,11 +964,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
     // - foo(::new Bar())
     if (Tok.is(tok::kw_new) || Tok.startsSequence(tok::coloncolon, 
tok::kw_new))
       return true;
-    if (Tok.is(TT_UnaryOperator) ||
-        (Style.isJavaScript() &&
-         Tok.isOneOf(tok::ellipsis, Keywords.kw_await))) {
-      return true;
-    }
+
     const auto *Previous = TokAfterLParen.Previous;
     assert(Previous); // IsOpeningBracket(Previous)
     if (Previous->Previous &&
@@ -976,6 +972,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
          Previous->Previous->is(tok::kw_switch))) {
       return false;
     }
+    if (Tok.is(TT_UnaryOperator) ||
+        (Style.isJavaScript() &&
+         Tok.isOneOf(tok::ellipsis, Keywords.kw_await))) {
+      return true;
+    }
     if (Previous->isNoneOf(TT_FunctionDeclarationLParen,
                            TT_LambdaDefinitionLParen) &&
         !IsFunctionCallParen(*Previous)) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b72a683ac1fff..f53f19c0df6be 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16,7 +16,6 @@ namespace test {
 namespace {
 
 class FormatTest : public test::FormatTestBase {};
-
 TEST_F(FormatTest, MessUp) {
   EXPECT_EQ("1 2 3", messUp("1 2 3"));
   EXPECT_EQ("1 2 3", messUp("1\n2\n3"));
@@ -26616,7 +26615,28 @@ TEST_F(FormatTest, UnbalancedAngleBrackets) {
 TEST_F(FormatTest, LambdaArrowAsTrailingReturnArrow) {
   verifyNoCrash("void foo()([] consteval -> int {}())");
 }
-
+TEST_F(FormatTest, BreakAfterOpenBracketIfUnary) {
+  FormatStyle Style = getLLVMStyle();
+  Style.ContinuationIndentWidth = 2;
+  Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
+  Style.BreakAfterOpenBracketIf = true;
+  Style.BreakBeforeCloseBracketIf = true;
+
+  verifyFormat("int main() {\n"
+               "  if (\n"
+               "    !printf(\"%s %s %s %s %s %s\",\n"
+               "            \"foobar\",\n"
+               "            \"foobar\",\n"
+               "            \"foobar\",\n"
+               "            \"foobar\",\n"
+               "            \"foobar\",\n"
+               "            \"foobar\")\n"
+               "  ) {\n"
+               "    return 1;\n"
+               "  }\n"
+               "}\n",
+               Style);
+}
 } // namespace
 } // namespace test
 } // namespace format

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to