[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 29 16:36:28 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang/include/clang/Format/Format.h clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/Format.cpp clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/ConfigParseTest.cpp clang/unittests/Format/FormatTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 08558d655..f4e48b7e3 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -834,16 +834,15 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
       /* For backward compatibility, use AlignAfterOpenBracket
        * in case AlignAfterControlStatement is not initialized */
       return Style.AlignAfterControlStatement == FormatStyle::BACSS_MultiLine ||
-        (Style.AlignAfterControlStatement == FormatStyle::BACSS_Default &&
-         Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak);
+             (Style.AlignAfterControlStatement == FormatStyle::BACSS_Default &&
+              Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak);
     }
-    if (IsOtherConditional(*Tok.Previous)) {
+    if (IsOtherConditional(*Tok.Previous))
       return Style.AlignAfterControlStatement == FormatStyle::BACSS_MultiLine;
-    }
     if (Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak ||
-       Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
+        Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
       return !Tok.Previous->is(TT_CastRParen) &&
-         !(Style.isJavaScript() && Tok.is(Keywords.kw_await));
+             !(Style.isJavaScript() && Tok.is(Keywords.kw_await));
     }
     return false;
   };
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e6a82a093..cd7e4cb06 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -202,8 +202,10 @@ template <> struct MappingTraits<FormatStyle::BraceWrappingFlags> {
   }
 };
 
-template <> struct ScalarEnumerationTraits<FormatStyle::BreakAfterControlStatementStyle> {
-  static void enumeration(IO &IO, FormatStyle::BreakAfterControlStatementStyle &Value) {
+template <>
+struct ScalarEnumerationTraits<FormatStyle::BreakAfterControlStatementStyle> {
+  static void enumeration(IO &IO,
+                          FormatStyle::BreakAfterControlStatementStyle &Value) {
     IO.enumCase(Value, "Default", FormatStyle::BACSS_Default);
     IO.enumCase(Value, "MultiLine", FormatStyle::BACSS_MultiLine);
     IO.enumCase(Value, "No", FormatStyle::BACSS_No);
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 39ddb63d4..881d40abf 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -6221,7 +6221,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
     const FormatToken *Previous = Right.MatchingParen->Previous;
     if (!Previous)
       return true;
-    if (Previous->isIf() || Previous->isOneOf(tok::kw_for, tok::kw_while, tok::kw_switch)) {
+    if (Previous->isIf() ||
+        Previous->isOneOf(tok::kw_for, tok::kw_while, tok::kw_switch)) {
       return Style.AlignAfterControlStatement == FormatStyle::BACSS_MultiLine;
     }
     return true;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 7841caefd..a314a0bff 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9797,7 +9797,6 @@ TEST_F(FormatTest, AlignAfterConditionalStatements) {
                "}",
                Style);
 
-
   Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
   Style.AlignAfterControlStatement = FormatStyle::BACSS_MultiLine;
 

``````````

</details>


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


More information about the cfe-commits mailing list