[clang] [clang-format] Fix BlockIndent compat mapping of AlignAfterOpenBracket (PR #207187)

Sergey Subbotin via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 2 06:39:22 PDT 2026


https://github.com/ssubbotin created https://github.com/llvm/llvm-project/pull/207187

be11e2b3d25 (#192283) replaced the `[[fallthrough]]` chain in the `AlignAfterOpenBracket` backward-compatibility switch with explicit per-case assignments. In the `BAS_BlockIndent` case the `BreakBeforeCloseBracket{BracedList,Function,If} = true` assignments are immediately overwritten with `false`, and `BreakAfterOpenBracket{BracedList,Function,If}` (previously inherited from the `BAS_AlwaysBreak` case via fallthrough) are never set. As a result, `AlignAfterOpenBracket: BlockIndent` parses to the same flag set as `Align`, silently dropping the block-indent style for existing configurations.

Restore the pre-#192283 mapping and pin the full BlockIndent flag mapping in ConfigParseTest so the compat shim cannot regress silently again.

Fixes #207186.

Note for the release branch: if #205920 (backport of #192283 to release/22.x) lands, this fix needs to be backported together with it.


>From d68bcf2d24b0e2eb24067d74c4b4d32682e19b0c Mon Sep 17 00:00:00 2001
From: Sergey Subbotin <ssubbotin at gmail.com>
Date: Thu, 2 Jul 2026 15:30:43 +0200
Subject: [PATCH] [clang-format] Fix BlockIndent compat mapping of
 AlignAfterOpenBracket

be11e2b3d25 (#192283) replaced the fallthrough chain in the
AlignAfterOpenBracket backward-compatibility switch with explicit
per-case assignments. In the BAS_BlockIndent case the
BreakBeforeCloseBracket{BracedList,Function,If} = true assignments are
immediately overwritten with false, and
BreakAfterOpenBracket{BracedList,Function,If} (previously inherited
from the BAS_AlwaysBreak case via fallthrough) are never set. As a
result, "AlignAfterOpenBracket: BlockIndent" parses to the same flag
set as "Align", silently dropping the block-indent style for existing
configurations.

Restore the pre-#192283 mapping and pin the full BlockIndent flag
mapping in ConfigParseTest so the compat shim cannot regress silently
again.
---
 clang/lib/Format/Format.cpp                | 10 ++++-----
 clang/unittests/Format/ConfigParseTest.cpp | 25 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ecfe5d2ce60d0..037111d8e9e5d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1159,14 +1159,14 @@ template <> struct MappingTraits<FormatStyle> {
         break;
       case BAS_BlockIndent:
         Style.AlignAfterOpenBracket = true;
+        Style.BreakAfterOpenBracketBracedList = true;
+        Style.BreakAfterOpenBracketFunction = true;
+        Style.BreakAfterOpenBracketIf = true;
+        Style.BreakAfterOpenBracketLoop = false;
+        Style.BreakAfterOpenBracketSwitch = false;
         Style.BreakBeforeCloseBracketBracedList = true;
         Style.BreakBeforeCloseBracketFunction = true;
         Style.BreakBeforeCloseBracketIf = true;
-        Style.BreakAfterOpenBracketLoop = false;
-        Style.BreakAfterOpenBracketSwitch = false;
-        Style.BreakBeforeCloseBracketBracedList = false;
-        Style.BreakBeforeCloseBracketFunction = false;
-        Style.BreakBeforeCloseBracketIf = false;
         Style.BreakBeforeCloseBracketLoop = false;
         Style.BreakBeforeCloseBracketSwitch = false;
         break;
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index eeaf5d3f66d96..1bfe3e2a61806 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -652,6 +652,31 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   CHECK_PARSE("AlignAfterOpenBracket: false", AlignAfterOpenBracket, false);
   CHECK_PARSE("AlignAfterOpenBracket: BlockIndent", AlignAfterOpenBracket,
               true);
+  // BlockIndent implies breaking after the open bracket and before the close
+  // bracket of braced lists, function calls/declarations, and if conditions.
+  Style.BreakAfterOpenBracketBracedList = false;
+  Style.BreakAfterOpenBracketFunction = false;
+  Style.BreakAfterOpenBracketIf = false;
+  Style.BreakAfterOpenBracketLoop = true;
+  Style.BreakAfterOpenBracketSwitch = true;
+  Style.BreakBeforeCloseBracketBracedList = false;
+  Style.BreakBeforeCloseBracketFunction = false;
+  Style.BreakBeforeCloseBracketIf = false;
+  Style.BreakBeforeCloseBracketLoop = true;
+  Style.BreakBeforeCloseBracketSwitch = true;
+  EXPECT_EQ(
+      0,
+      parseConfiguration("AlignAfterOpenBracket: BlockIndent", &Style).value());
+  EXPECT_TRUE(Style.BreakAfterOpenBracketBracedList);
+  EXPECT_TRUE(Style.BreakAfterOpenBracketFunction);
+  EXPECT_TRUE(Style.BreakAfterOpenBracketIf);
+  EXPECT_FALSE(Style.BreakAfterOpenBracketLoop);
+  EXPECT_FALSE(Style.BreakAfterOpenBracketSwitch);
+  EXPECT_TRUE(Style.BreakBeforeCloseBracketBracedList);
+  EXPECT_TRUE(Style.BreakBeforeCloseBracketFunction);
+  EXPECT_TRUE(Style.BreakBeforeCloseBracketIf);
+  EXPECT_FALSE(Style.BreakBeforeCloseBracketLoop);
+  EXPECT_FALSE(Style.BreakBeforeCloseBracketSwitch);
   Style.AlignAfterOpenBracket = false;
   CHECK_PARSE("AlignAfterOpenBracket: true", AlignAfterOpenBracket, true);
 



More information about the cfe-commits mailing list