[clang] [clang-format] Add BreakParametersAfter formatting option (PR #181281)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 19 13:00:25 PDT 2026
https://github.com/Ezlanding1 updated https://github.com/llvm/llvm-project/pull/181281
>From 9e7404121331ce53390aeb5d21d927fb5eb0e180 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Thu, 12 Feb 2026 19:55:05 -0500
Subject: [PATCH 01/13] Add MaxParametersOnLine format option
---
clang/docs/ClangFormatStyleOptions.rst | 31 ++++++++++++++++++++++++++
clang/include/clang/Format/Format.h | 30 +++++++++++++++++++++++++
clang/lib/Format/Format.cpp | 1 +
3 files changed, 62 insertions(+)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 54c085dff2840..06ed5d1239919 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5487,6 +5487,37 @@ the configuration (without a prefix: ``Auto``).
return i;
}
+.. _MaxParametersOnLine:
+
+**MaxParametersOnLine** (``Unsigned``) :versionbadge:`clang-format 23` :ref:`¶ <MaxParametersOnLine>`
+ The maximum amount of parameters that may appear on a single line in a
+ function declaration. This option can be used with ``BPPS_OnePerLine`` to
+ put every parameter on its own line if the function has more than
+ ``MaxParametersOnLine`` parameters. If this option is 0, there is no maximum.
+
+ .. code-block:: c++
+
+ MaxParametersOnLine: 3
+ BinPackParameters: BPPS_BinPack
+
+ void foo(int a, int b, int c);
+
+ void foo(int a, int b, int c,
+ int d);
+
+ void foo(int a, int b, int c,
+ int d, int e, int f,
+ int g, int h, int i);
+
+ BinPackParameters: BPPS_OnePerLine
+
+ void foo(int a, int b, int c);
+
+ void foo(int a,
+ int b,
+ int c,
+ int d);
+
.. _NamespaceIndentation:
**NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7` :ref:`¶ <NamespaceIndentation>`
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 48ce5aa2bdfa1..eb4c407852c4b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1361,6 +1361,35 @@ struct FormatStyle {
/// \version 3.7
BinPackParametersStyle BinPackParameters;
+ /// The maximum amount of parameters that may appear on a single line in a
+ /// function declaration. This option can be used with \c BPPS_OnePerLine to
+ /// put every parameter on its own line if the function has more than
+ /// \c MaxParametersOnLine parameters. If this option is 0, there is no maximum.
+ /// \code
+ /// MaxParametersOnLine: 3
+ /// BinPackParameters: BPPS_BinPack
+ ///
+ /// void foo(int a, int b, int c);
+ ///
+ /// void foo(int a, int b, int c,
+ /// int d);
+ ///
+ /// void foo(int a, int b, int c,
+ /// int d, int e, int f,
+ /// int g, int h, int i);
+ ///
+ /// BinPackParameters: BPPS_OnePerLine
+ ///
+ /// void foo(int a, int b, int c);
+ ///
+ /// void foo(int a,
+ /// int b,
+ /// int c,
+ /// int d);
+ /// \endcode
+ /// \version 23
+ unsigned MaxParametersOnLine;
+
/// Styles for adding spacing around ``:`` in bitfield definitions.
enum BitFieldColonSpacingStyle : int8_t {
/// Add one space on each side of the ``:``
@@ -5952,6 +5981,7 @@ struct FormatStyle {
BinPackArguments == R.BinPackArguments &&
BinPackLongBracedList == R.BinPackLongBracedList &&
BinPackParameters == R.BinPackParameters &&
+ MaxParametersOnLine == R.MaxParametersOnLine &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 42190604b3881..19f15f98001e7 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1440,6 +1440,7 @@ template <> struct MappingTraits<FormatStyle> {
Style.WhitespaceSensitiveMacros);
IO.mapOptional("WrapNamespaceBodyWithEmptyLines",
Style.WrapNamespaceBodyWithEmptyLines);
+ IO.mapOptional("MaxParametersOnLine", Style.MaxParametersOnLine);
// If AlwaysBreakAfterDefinitionReturnType was specified but
// BreakAfterReturnType was not, initialize the latter from the former for
>From bec9f923fa94e9b95ea93edd69d48e8fd060aa29 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Thu, 12 Feb 2026 20:08:02 -0500
Subject: [PATCH 02/13] Implement MaxParametersOnLine format option
---
clang/lib/Format/TokenAnnotator.cpp | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 5af9d26f7a84d..9f4ee06fe3dbb 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4262,6 +4262,26 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
ChildSize + Current->SpacesRequiredBefore;
}
+ if (Style.MaxParametersOnLine > 0 &&
+ Current->is(TT_FunctionDeclarationLParen) &&
+ Current->ParameterCount > Style.MaxParametersOnLine) {
+ const auto *RParen = Current->MatchingParen;
+ unsigned CurrentParamNum = 0;
+ for (auto *ParamTok = Current->Next; ParamTok && ParamTok != RParen;
+ ParamTok = ParamTok->Next) {
+ if (ParamTok->opensScope()) {
+ ParamTok = ParamTok->MatchingParen;
+ continue;
+ }
+
+ if (ParamTok->is(tok::comma) && ParamTok->Next &&
+ (++CurrentParamNum % Style.MaxParametersOnLine) == 0) {
+ ParamTok->Next->MustBreakBefore = true;
+ ParamTok->Next->CanBreakBefore = true;
+ }
+ }
+ }
+
if (Current->is(TT_ControlStatementLBrace)) {
if (Style.ColumnLimit > 0 &&
Style.BraceWrapping.AfterControlStatement ==
>From 09a2b9d7c103a63e951b40d530aa26adf010d3b2 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Mon, 16 Feb 2026 16:07:52 -0500
Subject: [PATCH 03/13] Improve parameter check with startsNextParameter()
---
clang/lib/Format/TokenAnnotator.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 9f4ee06fe3dbb..9819761cd2339 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4274,10 +4274,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
continue;
}
- if (ParamTok->is(tok::comma) && ParamTok->Next &&
+ if (startsNextParameter(*ParamTok, Style) &&
(++CurrentParamNum % Style.MaxParametersOnLine) == 0) {
- ParamTok->Next->MustBreakBefore = true;
- ParamTok->Next->CanBreakBefore = true;
+ ParamTok->MustBreakBefore = true;
+ ParamTok->CanBreakBefore = true;
}
}
}
>From 28ec6196b8ffecdfa2a880262b70c4b04df7c6b1 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Mon, 16 Feb 2026 16:43:31 -0500
Subject: [PATCH 04/13] Apply MaxParametersOnLine option to all parenthesized
parameter lists
---
clang/lib/Format/TokenAnnotator.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 9819761cd2339..e60d6df3dac03 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4263,7 +4263,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
}
if (Style.MaxParametersOnLine > 0 &&
- Current->is(TT_FunctionDeclarationLParen) &&
+ Current->is(tok::l_paren) &&
Current->ParameterCount > Style.MaxParametersOnLine) {
const auto *RParen = Current->MatchingParen;
unsigned CurrentParamNum = 0;
>From 8939af271b48daaa83575ab1f349198b30715ad3 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Mon, 16 Feb 2026 16:49:00 -0500
Subject: [PATCH 05/13] Break every parameter and rename to
BreakParametersAfter
---
clang/docs/ClangFormatStyleOptions.rst | 62 +++++++++++++-------------
clang/include/clang/Format/Format.h | 60 ++++++++++++-------------
clang/lib/Format/Format.cpp | 2 +-
clang/lib/Format/TokenAnnotator.cpp | 8 ++--
4 files changed, 65 insertions(+), 67 deletions(-)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 06ed5d1239919..f9daf465166d5 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3938,6 +3938,37 @@ the configuration (without a prefix: ``Auto``).
+.. _BreakParametersAfter:
+
+**BreakParametersAfter** (``Unsigned``) :versionbadge:`clang-format 23` :ref:`¶ <BreakParametersAfter>`
+ If set to a value greater than 0, any parenthesized parameter or argument
+ list with more parameters than the specified number will be formatted with
+ one parameter per line. This applies to all parameter-like lists enclosed
+ in parentheses, including function declarations, function definitions,
+ function calls, and comma expressions.
+
+ .. code-block:: c++
+
+ BreakParametersAfter: 3
+
+ void foo(int a);
+
+ void bar(int a, int b, int c);
+
+ void baz(int a,
+ int b,
+ int c,
+ int d);
+
+ foo(1);
+
+ bar(1, 2, 3);
+
+ baz(1,
+ 2,
+ 3,
+ 4);
+
.. _BreakStringLiterals:
**BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <BreakStringLiterals>`
@@ -5487,37 +5518,6 @@ the configuration (without a prefix: ``Auto``).
return i;
}
-.. _MaxParametersOnLine:
-
-**MaxParametersOnLine** (``Unsigned``) :versionbadge:`clang-format 23` :ref:`¶ <MaxParametersOnLine>`
- The maximum amount of parameters that may appear on a single line in a
- function declaration. This option can be used with ``BPPS_OnePerLine`` to
- put every parameter on its own line if the function has more than
- ``MaxParametersOnLine`` parameters. If this option is 0, there is no maximum.
-
- .. code-block:: c++
-
- MaxParametersOnLine: 3
- BinPackParameters: BPPS_BinPack
-
- void foo(int a, int b, int c);
-
- void foo(int a, int b, int c,
- int d);
-
- void foo(int a, int b, int c,
- int d, int e, int f,
- int g, int h, int i);
-
- BinPackParameters: BPPS_OnePerLine
-
- void foo(int a, int b, int c);
-
- void foo(int a,
- int b,
- int c,
- int d);
-
.. _NamespaceIndentation:
**NamespaceIndentation** (``NamespaceIndentationKind``) :versionbadge:`clang-format 3.7` :ref:`¶ <NamespaceIndentation>`
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index eb4c407852c4b..abbf2fee897f1 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1361,35 +1361,6 @@ struct FormatStyle {
/// \version 3.7
BinPackParametersStyle BinPackParameters;
- /// The maximum amount of parameters that may appear on a single line in a
- /// function declaration. This option can be used with \c BPPS_OnePerLine to
- /// put every parameter on its own line if the function has more than
- /// \c MaxParametersOnLine parameters. If this option is 0, there is no maximum.
- /// \code
- /// MaxParametersOnLine: 3
- /// BinPackParameters: BPPS_BinPack
- ///
- /// void foo(int a, int b, int c);
- ///
- /// void foo(int a, int b, int c,
- /// int d);
- ///
- /// void foo(int a, int b, int c,
- /// int d, int e, int f,
- /// int g, int h, int i);
- ///
- /// BinPackParameters: BPPS_OnePerLine
- ///
- /// void foo(int a, int b, int c);
- ///
- /// void foo(int a,
- /// int b,
- /// int c,
- /// int d);
- /// \endcode
- /// \version 23
- unsigned MaxParametersOnLine;
-
/// Styles for adding spacing around ``:`` in bitfield definitions.
enum BitFieldColonSpacingStyle : int8_t {
/// Add one space on each side of the ``:``
@@ -2841,6 +2812,35 @@ struct FormatStyle {
/// \version 7
BreakInheritanceListStyle BreakInheritanceList;
+ /// If set to a value greater than 0, any parenthesized parameter or argument
+ /// list with more parameters than the specified number will be formatted with
+ /// one parameter per line. This applies to all parameter-like lists enclosed
+ /// in parentheses, including function declarations, function definitions,
+ /// function calls, and comma expressions.
+ /// \code
+ /// BreakParametersAfter: 3
+ ///
+ /// void foo(int a);
+ ///
+ /// void bar(int a, int b, int c);
+ ///
+ /// void baz(int a,
+ /// int b,
+ /// int c,
+ /// int d);
+ ///
+ /// foo(1);
+ ///
+ /// bar(1, 2, 3);
+ ///
+ /// baz(1,
+ /// 2,
+ /// 3,
+ /// 4);
+ /// \endcode
+ /// \version 23
+ unsigned BreakParametersAfter;
+
/// The template declaration breaking style to use.
/// \version 19
BreakTemplateDeclarationsStyle BreakTemplateDeclarations;
@@ -5981,7 +5981,6 @@ struct FormatStyle {
BinPackArguments == R.BinPackArguments &&
BinPackLongBracedList == R.BinPackLongBracedList &&
BinPackParameters == R.BinPackParameters &&
- MaxParametersOnLine == R.MaxParametersOnLine &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
@@ -6013,6 +6012,7 @@ struct FormatStyle {
BreakFunctionDefinitionParameters ==
R.BreakFunctionDefinitionParameters &&
BreakInheritanceList == R.BreakInheritanceList &&
+ BreakParametersAfter == R.BreakParametersAfter &&
BreakStringLiterals == R.BreakStringLiterals &&
BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 19f15f98001e7..c02e82f86bace 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1440,7 +1440,7 @@ template <> struct MappingTraits<FormatStyle> {
Style.WhitespaceSensitiveMacros);
IO.mapOptional("WrapNamespaceBodyWithEmptyLines",
Style.WrapNamespaceBodyWithEmptyLines);
- IO.mapOptional("MaxParametersOnLine", Style.MaxParametersOnLine);
+ IO.mapOptional("BreakParametersAfter", Style.BreakParametersAfter);
// If AlwaysBreakAfterDefinitionReturnType was specified but
// BreakAfterReturnType was not, initialize the latter from the former for
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index e60d6df3dac03..52405f8ff7ca1 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4262,11 +4262,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
ChildSize + Current->SpacesRequiredBefore;
}
- if (Style.MaxParametersOnLine > 0 &&
+ if (Style.BreakParametersAfter > 0 &&
Current->is(tok::l_paren) &&
- Current->ParameterCount > Style.MaxParametersOnLine) {
+ Current->ParameterCount > Style.BreakParametersAfter) {
const auto *RParen = Current->MatchingParen;
- unsigned CurrentParamNum = 0;
for (auto *ParamTok = Current->Next; ParamTok && ParamTok != RParen;
ParamTok = ParamTok->Next) {
if (ParamTok->opensScope()) {
@@ -4274,8 +4273,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
continue;
}
- if (startsNextParameter(*ParamTok, Style) &&
- (++CurrentParamNum % Style.MaxParametersOnLine) == 0) {
+ if (startsNextParameter(*ParamTok, Style)) {
ParamTok->MustBreakBefore = true;
ParamTok->CanBreakBefore = true;
}
>From 67c969493425785bc9c0fa160647d1c68d0c6fb9 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Mon, 16 Feb 2026 22:22:03 -0500
Subject: [PATCH 06/13] Add unit tests for BreakParametersAfter
---
clang/lib/Format/Format.cpp | 1 +
clang/unittests/Format/ConfigParseTest.cpp | 1 +
clang/unittests/Format/FormatTest.cpp | 80 ++++++++++++++++++++++
3 files changed, 82 insertions(+)
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c02e82f86bace..4763982c26008 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1830,6 +1830,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
LLVMStyle.BreakFunctionDefinitionParameters = false;
LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
+ LLVMStyle.BreakParametersAfter = 0;
LLVMStyle.BreakStringLiterals = true;
LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
LLVMStyle.ColumnLimit = 80;
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 3cff71608cba4..f56e143d60a42 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -286,6 +286,7 @@ TEST(ConfigParseTest, ParsesConfigurationIntegers) {
CHECK_PARSE_INT(BracedInitializerIndentWidth);
CHECK_PARSE_INT(PPIndentWidth);
+ CHECK_PARSE_UNSIGNED(BreakParametersAfter);
CHECK_PARSE_UNSIGNED(ColumnLimit);
CHECK_PARSE_UNSIGNED(ConstructorInitializerIndentWidth);
CHECK_PARSE_UNSIGNED(ContinuationIndentWidth);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index abe546542b4af..51ebfa505f889 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8152,6 +8152,86 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
" int B)\n"
" : m_A(A), m_B(B) {}",
Input, Style);
+
+ Style.BinPackParameters = FormatStyle::BPPS_BinPack;
+ Style.BreakFunctionDefinitionParameters = false;
+ Style.BreakParametersAfter = 2;
+ verifyFormat("void functionDecl(paramA, paramB);\n"
+ "void functionDecl(paramA,\n"
+ " paramB,\n"
+ " paramC);\n"
+ "void functionDecl(paramA,\n"
+ " paramB,\n"
+ " paramC,\n"
+ " paramD,\n"
+ " paramE);\n"
+ "void functionDefinition(int A, int B) {}\n"
+ "void functionDefinition(int A,\n"
+ " int B,\n"
+ " int C) {}\n"
+ "Class::Class(int A, int B) {}\n"
+ "Class::Class(int A,\n"
+ " int B,\n"
+ " int C) {}\n"
+ "call(a, b);\n"
+ "call(a,\n"
+ " b,\n"
+ " c);\n"
+ "new Class(a, b);\n"
+ "new Class(a,\n"
+ " b,\n"
+ " c);\n"
+ "int x = (a, b);\n"
+ "int y = (a,\n"
+ " b,\n"
+ " c);",
+ Style);
+ Style.BreakParametersAfter = 4;
+ verifyFormat("void functionDecl(paramA);\n"
+ "void functionDecl(paramA, paramB);\n"
+ "void functionDecl(paramA, paramB, paramC);\n"
+ "void functionDecl(paramA, paramB, paramC, paramD);\n"
+ "void functionDecl(paramA,\n"
+ " paramB,\n"
+ " paramC,\n"
+ " paramD,\n"
+ " paramE);\n"
+ "void functionDecl(paramA,\n"
+ " paramB,\n"
+ " paramC,\n"
+ " paramD,\n"
+ " paramE,\n"
+ " paramF);\n"
+ "void functionDefinition(int A, int B, int C, int D) {}\n"
+ "void functionDefinition(int A,\n"
+ " int B,\n"
+ " int C,\n"
+ " int D,\n"
+ " int E) {}\n"
+ "Class::Class(int A, int B) {}\n"
+ "Class::Class(int A, int B, int C, int D) {}\n"
+ "Class::Class(int A,\n"
+ " int B,\n"
+ " int C,\n"
+ " int D,\n"
+ " int E) {}\n"
+ "call(a,\n"
+ " b,\n"
+ " c,\n"
+ " d,\n"
+ " e);\n"
+ "new Class(a,\n"
+ " b,\n"
+ " c,\n"
+ " d,\n"
+ " e);\n"
+ "int y = (a,\n"
+ " b,\n"
+ " c,\n"
+ " d,\n"
+ " e);",
+ Style);
+ Style.BreakParametersAfter = 0;
}
TEST_F(FormatTest, BreakBeforeInlineASMColon) {
>From 88128e792e85a581f57e1b3fb2881bd26f242778 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Mon, 16 Feb 2026 23:10:05 -0500
Subject: [PATCH 07/13] Calculate BreakParametersAfter from first token - Fixes
bugs where a tok::l_paren starts the line, for instance a line beginning with
a comma expression or a C# tuple
---
clang/lib/Format/TokenAnnotator.cpp | 9 ++++-----
clang/unittests/Format/FormatTest.cpp | 13 +++++++++++--
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 52405f8ff7ca1..fa190c535c576 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4262,11 +4262,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
ChildSize + Current->SpacesRequiredBefore;
}
- if (Style.BreakParametersAfter > 0 &&
- Current->is(tok::l_paren) &&
- Current->ParameterCount > Style.BreakParametersAfter) {
- const auto *RParen = Current->MatchingParen;
- for (auto *ParamTok = Current->Next; ParamTok && ParamTok != RParen;
+ if (Style.BreakParametersAfter > 0 && Prev->is(tok::l_paren) &&
+ Prev->ParameterCount > Style.BreakParametersAfter) {
+ const auto *RParen = Prev->MatchingParen;
+ for (auto *ParamTok = Current; ParamTok && ParamTok != RParen;
ParamTok = ParamTok->Next) {
if (ParamTok->opensScope()) {
ParamTok = ParamTok->MatchingParen;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 51ebfa505f889..405ce9f4c3e23 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8184,7 +8184,11 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
"int x = (a, b);\n"
"int y = (a,\n"
" b,\n"
- " c);",
+ " c);\n"
+ "(a, b);\n"
+ "(a,\n"
+ " b,\n"
+ " c);",
Style);
Style.BreakParametersAfter = 4;
verifyFormat("void functionDecl(paramA);\n"
@@ -8229,7 +8233,12 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
" b,\n"
" c,\n"
" d,\n"
- " e);",
+ " e);\n"
+ "(a,\n"
+ " b,\n"
+ " c,\n"
+ " d,\n"
+ " e);",
Style);
Style.BreakParametersAfter = 0;
}
>From 399f51856d414138343668000317bd5d22f4a00c Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Fri, 6 Mar 2026 15:54:32 -0500
Subject: [PATCH 08/13] Fix BreakAfter options based on code review feedback
---
clang/docs/ClangFormatStyleOptions.rst | 227 +++++++++++++---------
clang/include/clang/Format/Format.h | 221 +++++++++++++--------
clang/lib/Format/ContinuationIndenter.cpp | 23 ++-
clang/lib/Format/Format.cpp | 50 ++++-
clang/lib/Format/FormatToken.cpp | 2 +-
clang/lib/Format/TokenAnnotator.cpp | 12 +-
clang/unittests/Format/FormatTest.cpp | 88 ++-------
7 files changed, 354 insertions(+), 269 deletions(-)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index f9daf465166d5..2375c0a376425 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2247,27 +2247,6 @@ the configuration (without a prefix: ``Auto``).
AttributeMacros: [__capability, __output, __unused]
-.. _BinPackArguments:
-
-**BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackArguments>`
- If ``false``, a function call's arguments will either be all on the
- same line or will have one line each.
-
- .. code-block:: c++
-
- true:
- void f() {
- f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
- }
-
- false:
- void f() {
- f(aaaaaaaaaaaaaaaaaaaa,
- aaaaaaaaaaaaaaaaaaaa,
- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
- }
-
.. _BinPackLongBracedList:
**BinPackLongBracedList** (``Boolean``) :versionbadge:`clang-format 21` :ref:`¶ <BinPackLongBracedList>`
@@ -2286,44 +2265,6 @@ the configuration (without a prefix: ``Auto``).
20,
21};
-.. _BinPackParameters:
-
-**BinPackParameters** (``BinPackParametersStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackParameters>`
- The bin pack parameters style to use.
-
- Possible values:
-
- * ``BPPS_BinPack`` (in configuration: ``BinPack``)
- Bin-pack parameters.
-
- .. code-block:: c++
-
- void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
- int ccccccccccccccccccccccccccccccccccccccccccc);
-
- * ``BPPS_OnePerLine`` (in configuration: ``OnePerLine``)
- Put all parameters on the current line if they fit.
- Otherwise, put each one on its own line.
-
- .. code-block:: c++
-
- void f(int a, int b, int c);
-
- void f(int a,
- int b,
- int ccccccccccccccccccccccccccccccccccccc);
-
- * ``BPPS_AlwaysOnePerLine`` (in configuration: ``AlwaysOnePerLine``)
- Always put each parameter on its own line.
-
- .. code-block:: c++
-
- void f(int a,
- int b,
- int c);
-
-
-
.. _BitFieldColonSpacing:
**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BitFieldColonSpacing>`
@@ -3938,37 +3879,6 @@ the configuration (without a prefix: ``Auto``).
-.. _BreakParametersAfter:
-
-**BreakParametersAfter** (``Unsigned``) :versionbadge:`clang-format 23` :ref:`¶ <BreakParametersAfter>`
- If set to a value greater than 0, any parenthesized parameter or argument
- list with more parameters than the specified number will be formatted with
- one parameter per line. This applies to all parameter-like lists enclosed
- in parentheses, including function declarations, function definitions,
- function calls, and comma expressions.
-
- .. code-block:: c++
-
- BreakParametersAfter: 3
-
- void foo(int a);
-
- void bar(int a, int b, int c);
-
- void baz(int a,
- int b,
- int c,
- int d);
-
- foo(1);
-
- bar(1, 2, 3);
-
- baz(1,
- 2,
- 3,
- 4);
-
.. _BreakStringLiterals:
**BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ <BreakStringLiterals>`
@@ -5867,6 +5777,71 @@ the configuration (without a prefix: ``Auto``).
# define BAR
#endif
+.. _PackArguments:
+
+**PackArguments** (``PackArgumentsStyle``) :versionbadge:`clang-format 23` :ref:`¶ <PackArguments>`
+ Options related to packing arguments of function calls.
+
+ Nested configuration flags:
+
+ Options related to packing arguments of function calls.
+
+ * ``BinPackArgumentsStyle BinPack`` :versionbadge:`clang-format 3.7`
+
+ The bin pack arguments style to use.
+
+ Possible values:
+
+ * ``BPAS_BinPack`` (in configuration: ``BinPack``)
+ Bin-pack arguments.
+
+ .. code-block:: c++
+
+ void f() {
+ f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
+ }
+
+ * ``BPAS_OnePerLine`` (in configuration: ``OnePerLine``)
+ Put all arguments on the current line if they fit.
+ Otherwise, put each one on its own line.
+
+ .. code-block:: c++
+
+ void f() {
+ f(aaaaaaaaaaaaaaaaaaaa,
+ aaaaaaaaaaaaaaaaaaaa,
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
+ }
+
+ * ``BPAS_UseBreakAfter`` (in configuration: ``UseBreakAfter``)
+ Use the ``BreakAfter`` option to handle argument packing instead.
+ If the ``BreakAfter`` limit is not exceeded, behave like ``BinPack``.
+
+
+ * ``unsigned BreakAfter`` :versionbadge:`clang-format 23`
+ An argument list with more arguments than the specified number will be
+ formatted with one argument per line. This option must be used with
+ ``BinPack: UseBreakAfter``.
+
+ .. code-block:: c++
+
+ PackArguments:
+ BinPack: UseBreakAfter
+ BreakAfter: 3
+
+ void f() {
+ foo(1);
+
+ bar(1, 2, 3);
+
+ baz(1,
+ 2,
+ 3,
+ 4);
+ }
+
+
.. _PackConstructorInitializers:
**PackConstructorInitializers** (``PackConstructorInitializersStyle``) :versionbadge:`clang-format 14` :ref:`¶ <PackConstructorInitializers>`
@@ -5940,6 +5915,78 @@ the configuration (without a prefix: ``Auto``).
+.. _PackParameters:
+
+**PackParameters** (``PackParametersStyle``) :versionbadge:`clang-format 23` :ref:`¶ <PackParameters>`
+ Options related to packing parameters of function declarations and
+ definitions.
+
+ Nested configuration flags:
+
+ Options related to packing parameters of function declarations and
+ definitions.
+
+ * ``BinPackParametersStyle BinPack`` :versionbadge:`clang-format 3.7`
+
+ The bin pack parameters style to use.
+
+ Possible values:
+
+ * ``BPPS_BinPack`` (in configuration: ``BinPack``)
+ Bin-pack parameters.
+
+ .. code-block:: c++
+
+ void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
+ int ccccccccccccccccccccccccccccccccccccccccccc);
+
+ * ``BPPS_OnePerLine`` (in configuration: ``OnePerLine``)
+ Put all parameters on the current line if they fit.
+ Otherwise, put each one on its own line.
+
+ .. code-block:: c++
+
+ void f(int a, int b, int c);
+
+ void f(int a,
+ int b,
+ int ccccccccccccccccccccccccccccccccccccc);
+
+ * ``BPPS_AlwaysOnePerLine`` (in configuration: ``AlwaysOnePerLine``)
+ Always put each parameter on its own line.
+
+ .. code-block:: c++
+
+ void f(int a,
+ int b,
+ int c);
+
+ * ``BPPS_UseBreakAfter`` (in configuration: ``UseBreakAfter``)
+ Use the ``BreakAfter`` option to handle parameter packing instead.
+ If the ``BreakAfter`` limit is not exceeded, behave like ``BinPack``.
+
+
+ * ``unsigned BreakAfter`` :versionbadge:`clang-format 23`
+ A parameter list with more parameters than the specified number will be
+ formatted with one parameter per line. This option must be used with
+ ``BinPack: UseBreakAfter``.
+
+ .. code-block:: c++
+
+ PackParameters:
+ BinPack: UseBreakAfter
+ BreakAfter: 3
+
+ void foo(int a);
+
+ void bar(int a, int b, int c);
+
+ void baz(int a,
+ int b,
+ int c,
+ int d);
+
+
.. _PenaltyBreakAssignment:
**PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` :ref:`¶ <PenaltyBreakAssignment>`
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index abbf2fee897f1..4b45e2133c61b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1295,25 +1295,6 @@ struct FormatStyle {
/// \version 12
std::vector<std::string> AttributeMacros;
- /// If ``false``, a function call's arguments will either be all on the
- /// same line or will have one line each.
- /// \code
- /// true:
- /// void f() {
- /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
- /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
- /// }
- ///
- /// false:
- /// void f() {
- /// f(aaaaaaaaaaaaaaaaaaaa,
- /// aaaaaaaaaaaaaaaaaaaa,
- /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
- /// }
- /// \endcode
- /// \version 3.7
- bool BinPackArguments;
-
/// If ``BinPackLongBracedList`` is ``true`` it overrides
/// ``BinPackArguments`` if there are 20 or more items in a braced
/// initializer list.
@@ -1330,37 +1311,6 @@ struct FormatStyle {
/// \version 21
bool BinPackLongBracedList;
- /// Different way to try to fit all parameters on a line.
- enum BinPackParametersStyle : int8_t {
- /// Bin-pack parameters.
- /// \code
- /// void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
- /// int ccccccccccccccccccccccccccccccccccccccccccc);
- /// \endcode
- BPPS_BinPack,
- /// Put all parameters on the current line if they fit.
- /// Otherwise, put each one on its own line.
- /// \code
- /// void f(int a, int b, int c);
- ///
- /// void f(int a,
- /// int b,
- /// int ccccccccccccccccccccccccccccccccccccc);
- /// \endcode
- BPPS_OnePerLine,
- /// Always put each parameter on its own line.
- /// \code
- /// void f(int a,
- /// int b,
- /// int c);
- /// \endcode
- BPPS_AlwaysOnePerLine,
- };
-
- /// The bin pack parameters style to use.
- /// \version 3.7
- BinPackParametersStyle BinPackParameters;
-
/// Styles for adding spacing around ``:`` in bitfield definitions.
enum BitFieldColonSpacingStyle : int8_t {
/// Add one space on each side of the ``:``
@@ -2812,35 +2762,6 @@ struct FormatStyle {
/// \version 7
BreakInheritanceListStyle BreakInheritanceList;
- /// If set to a value greater than 0, any parenthesized parameter or argument
- /// list with more parameters than the specified number will be formatted with
- /// one parameter per line. This applies to all parameter-like lists enclosed
- /// in parentheses, including function declarations, function definitions,
- /// function calls, and comma expressions.
- /// \code
- /// BreakParametersAfter: 3
- ///
- /// void foo(int a);
- ///
- /// void bar(int a, int b, int c);
- ///
- /// void baz(int a,
- /// int b,
- /// int c,
- /// int d);
- ///
- /// foo(1);
- ///
- /// bar(1, 2, 3);
- ///
- /// baz(1,
- /// 2,
- /// 3,
- /// 4);
- /// \endcode
- /// \version 23
- unsigned BreakParametersAfter;
-
/// The template declaration breaking style to use.
/// \version 19
BreakTemplateDeclarationsStyle BreakTemplateDeclarations;
@@ -4250,6 +4171,72 @@ struct FormatStyle {
/// \version 21
std::string OneLineFormatOffRegex;
+ /// Different ways to try to fit all arguments on a line.
+ enum BinPackArgumentsStyle : int8_t {
+ /// Bin-pack arguments.
+ /// \code
+ /// void f() {
+ /// f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,
+ /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
+ /// }
+ /// \endcode
+ BPAS_BinPack,
+ /// Put all arguments on the current line if they fit.
+ /// Otherwise, put each one on its own line.
+ /// \code
+ /// void f() {
+ /// f(aaaaaaaaaaaaaaaaaaaa,
+ /// aaaaaaaaaaaaaaaaaaaa,
+ /// aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);
+ /// }
+ /// \endcode
+ BPAS_OnePerLine,
+ /// Use the ``BreakAfter`` option to handle argument packing instead.
+ /// If the ``BreakAfter`` limit is not exceeded, behave like ``BinPack``.
+ BPAS_UseBreakAfter
+ };
+
+ /// Options related to packing arguments of function calls.
+ struct PackArgumentsStyle {
+
+ /// The bin pack arguments style to use.
+ /// \version 3.7
+ BinPackArgumentsStyle BinPack;
+
+ /// An argument list with more arguments than the specified number will be
+ /// formatted with one argument per line. This option must be used with
+ /// ``BinPack: UseBreakAfter``.
+ /// \code
+ /// PackArguments:
+ /// BinPack: UseBreakAfter
+ /// BreakAfter: 3
+ ///
+ /// void f() {
+ /// foo(1);
+ ///
+ /// bar(1, 2, 3);
+ ///
+ /// baz(1,
+ /// 2,
+ /// 3,
+ /// 4);
+ /// }
+ /// \endcode
+ /// \version 23
+ unsigned BreakAfter;
+
+ bool operator==(const PackArgumentsStyle &R) const {
+ return BinPack == R.BinPack && BreakAfter == R.BreakAfter;
+ }
+ bool operator!=(const PackArgumentsStyle &R) const {
+ return !operator==(R);
+ }
+ };
+
+ /// Options related to packing arguments of function calls.
+ /// \version 23
+ PackArgumentsStyle PackArguments;
+
/// Different ways to try to fit all constructor initializers on a line.
enum PackConstructorInitializersStyle : int8_t {
/// Always put each constructor initializer on its own line.
@@ -4312,6 +4299,77 @@ struct FormatStyle {
/// \version 14
PackConstructorInitializersStyle PackConstructorInitializers;
+ /// Different ways to try to fit all parameters on a line.
+ enum BinPackParametersStyle : int8_t {
+ /// Bin-pack parameters.
+ /// \code
+ /// void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
+ /// int ccccccccccccccccccccccccccccccccccccccccccc);
+ /// \endcode
+ BPPS_BinPack,
+ /// Put all parameters on the current line if they fit.
+ /// Otherwise, put each one on its own line.
+ /// \code
+ /// void f(int a, int b, int c);
+ ///
+ /// void f(int a,
+ /// int b,
+ /// int ccccccccccccccccccccccccccccccccccccc);
+ /// \endcode
+ BPPS_OnePerLine,
+ /// Always put each parameter on its own line.
+ /// \code
+ /// void f(int a,
+ /// int b,
+ /// int c);
+ /// \endcode
+ BPPS_AlwaysOnePerLine,
+ /// Use the ``BreakAfter`` option to handle parameter packing instead.
+ /// If the ``BreakAfter`` limit is not exceeded, behave like ``BinPack``.
+ BPPS_UseBreakAfter
+ };
+
+ /// Options related to packing parameters of function declarations and
+ /// definitions.
+ struct PackParametersStyle {
+
+ /// The bin pack parameters style to use.
+ /// \version 3.7
+ BinPackParametersStyle BinPack;
+
+ /// A parameter list with more parameters than the specified number will be
+ /// formatted with one parameter per line. This option must be used with
+ /// ``BinPack: UseBreakAfter``.
+ /// \code
+ /// PackParameters:
+ /// BinPack: UseBreakAfter
+ /// BreakAfter: 3
+ ///
+ /// void foo(int a);
+ ///
+ /// void bar(int a, int b, int c);
+ ///
+ /// void baz(int a,
+ /// int b,
+ /// int c,
+ /// int d);
+ /// \endcode
+ /// \version 23
+ unsigned BreakAfter;
+
+ bool operator==(const PackParametersStyle &R) const {
+ return BinPack == R.BinPack && BreakAfter == R.BreakAfter;
+ }
+ bool operator!=(const PackParametersStyle &R) const {
+ return !operator==(R);
+ }
+ };
+
+ /// Options related to packing parameters of function declarations and
+ /// definitions.
+ /// \version 23
+ PackParametersStyle PackParameters;
+
/// The penalty for breaking around an assignment operator.
/// \version 5
unsigned PenaltyBreakAssignment;
@@ -5978,9 +6036,7 @@ struct FormatStyle {
AlwaysBreakBeforeMultilineStrings ==
R.AlwaysBreakBeforeMultilineStrings &&
AttributeMacros == R.AttributeMacros &&
- BinPackArguments == R.BinPackArguments &&
BinPackLongBracedList == R.BinPackLongBracedList &&
- BinPackParameters == R.BinPackParameters &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
@@ -6012,7 +6068,6 @@ struct FormatStyle {
BreakFunctionDefinitionParameters ==
R.BreakFunctionDefinitionParameters &&
BreakInheritanceList == R.BreakInheritanceList &&
- BreakParametersAfter == R.BreakParametersAfter &&
BreakStringLiterals == R.BreakStringLiterals &&
BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
@@ -6074,7 +6129,9 @@ struct FormatStyle {
ObjCSpaceAfterProperty == R.ObjCSpaceAfterProperty &&
ObjCSpaceBeforeProtocolList == R.ObjCSpaceBeforeProtocolList &&
OneLineFormatOffRegex == R.OneLineFormatOffRegex &&
+ PackArguments == R.PackArguments &&
PackConstructorInitializers == R.PackConstructorInitializers &&
+ PackParameters == R.PackParameters &&
PenaltyBreakAssignment == R.PenaltyBreakAssignment &&
PenaltyBreakBeforeFirstCallParameter ==
R.PenaltyBreakBeforeFirstCallParameter &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index fc5e1000ad750..8079adb7d0e79 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -514,7 +514,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
// completely unnecessary line break after a template type that isn't
// line-wrapped.
(Previous.NestingLevel == 1 ||
- Style.BinPackParameters == FormatStyle::BPPS_BinPack)) ||
+ (Style.PackParameters.BinPack == FormatStyle::BPPS_BinPack ||
+ Style.PackParameters.BinPack == FormatStyle::BPPS_UseBreakAfter))) ||
(Style.BreakBeforeTernaryOperators && Current.is(TT_ConditionalExpr) &&
Previous.isNot(tok::question)) ||
(!Style.BreakBeforeTernaryOperators &&
@@ -2111,11 +2112,12 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
NewIndent = CurrentState.LastSpace + Style.ContinuationIndentWidth;
}
const FormatToken *NextNonComment = Current.getNextNonComment();
- AvoidBinPacking = EndsInComma || Current.is(TT_DictLiteral) ||
- Style.isProto() || !Style.BinPackArguments ||
- (NextNonComment && NextNonComment->isOneOf(
- TT_DesignatedInitializerPeriod,
- TT_DesignatedInitializerLSquare));
+ AvoidBinPacking =
+ EndsInComma || Current.is(TT_DictLiteral) || Style.isProto() ||
+ Style.PackArguments.BinPack == FormatStyle::BPAS_OnePerLine ||
+ (NextNonComment &&
+ NextNonComment->isOneOf(TT_DesignatedInitializerPeriod,
+ TT_DesignatedInitializerLSquare));
BreakBeforeParameter = EndsInComma;
if (Current.ParameterCount > 1)
NestedBlockIndent = std::max(NestedBlockIndent, State.Column + 1);
@@ -2148,12 +2150,14 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
// for backwards compatibility.
bool ObjCBinPackProtocolList =
(Style.ObjCBinPackProtocolList == FormatStyle::BPS_Auto &&
- Style.BinPackParameters == FormatStyle::BPPS_BinPack) ||
+ (Style.PackParameters.BinPack == FormatStyle::BPPS_BinPack ||
+ Style.PackParameters.BinPack == FormatStyle::BPPS_UseBreakAfter)) ||
Style.ObjCBinPackProtocolList == FormatStyle::BPS_Always;
bool BinPackDeclaration =
(State.Line->Type != LT_ObjCDecl &&
- Style.BinPackParameters == FormatStyle::BPPS_BinPack) ||
+ (Style.PackParameters.BinPack == FormatStyle::BPPS_BinPack ||
+ Style.PackParameters.BinPack == FormatStyle::BPPS_UseBreakAfter)) ||
(State.Line->Type == LT_ObjCDecl && ObjCBinPackProtocolList);
bool GenericSelection =
@@ -2164,7 +2168,8 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
(CurrentState.IsCSharpGenericTypeConstraint) || GenericSelection ||
(Style.isJavaScript() && EndsInComma) ||
(State.Line->MustBeDeclaration && !BinPackDeclaration) ||
- (!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||
+ (!State.Line->MustBeDeclaration &&
+ Style.PackArguments.BinPack == FormatStyle::BPAS_OnePerLine) ||
(Style.ExperimentalAutoDetectBinPacking &&
(Current.is(PPK_OnePerLine) ||
(!BinPackInconclusiveFunctions && Current.is(PPK_Inconclusive))));
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 4763982c26008..c5fa12a78162f 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -146,12 +146,25 @@ template <> struct ScalarEnumerationTraits<FormatStyle::BinaryOperatorStyle> {
}
};
+template <> struct ScalarEnumerationTraits<FormatStyle::BinPackArgumentsStyle> {
+ static void enumeration(IO &IO, FormatStyle::BinPackArgumentsStyle &Value) {
+ IO.enumCase(Value, "BinPack", FormatStyle::BPAS_BinPack);
+ IO.enumCase(Value, "OnePerLine", FormatStyle::BPAS_OnePerLine);
+ IO.enumCase(Value, "UseBreakAfter", FormatStyle::BPAS_UseBreakAfter);
+
+ // For backward compatibility.
+ IO.enumCase(Value, "true", FormatStyle::BPAS_BinPack);
+ IO.enumCase(Value, "false", FormatStyle::BPAS_OnePerLine);
+ }
+};
+
template <>
struct ScalarEnumerationTraits<FormatStyle::BinPackParametersStyle> {
static void enumeration(IO &IO, FormatStyle::BinPackParametersStyle &Value) {
IO.enumCase(Value, "BinPack", FormatStyle::BPPS_BinPack);
IO.enumCase(Value, "OnePerLine", FormatStyle::BPPS_OnePerLine);
IO.enumCase(Value, "AlwaysOnePerLine", FormatStyle::BPPS_AlwaysOnePerLine);
+ IO.enumCase(Value, "UseBreakAfter", FormatStyle::BPPS_UseBreakAfter);
// For backward compatibility.
IO.enumCase(Value, "true", FormatStyle::BPPS_BinPack);
@@ -593,6 +606,13 @@ template <> struct ScalarEnumerationTraits<FormatStyle::OperandAlignmentStyle> {
}
};
+template <> struct MappingTraits<FormatStyle::PackParametersStyle> {
+ static void mapping(IO &IO, FormatStyle::PackParametersStyle &Value) {
+ IO.mapOptional("BinPack", Value.BinPack);
+ IO.mapOptional("BreakAfter", Value.BreakAfter);
+ }
+};
+
template <>
struct ScalarEnumerationTraits<FormatStyle::PackConstructorInitializersStyle> {
static void
@@ -605,6 +625,13 @@ struct ScalarEnumerationTraits<FormatStyle::PackConstructorInitializersStyle> {
}
};
+template <> struct MappingTraits<FormatStyle::PackArgumentsStyle> {
+ static void mapping(IO &IO, FormatStyle::PackArgumentsStyle &Value) {
+ IO.mapOptional("BinPack", Value.BinPack);
+ IO.mapOptional("BreakAfter", Value.BreakAfter);
+ }
+};
+
template <> struct ScalarEnumerationTraits<FormatStyle::PointerAlignmentStyle> {
static void enumeration(IO &IO, FormatStyle::PointerAlignmentStyle &Value) {
IO.enumCase(Value, "Middle", FormatStyle::PAS_Middle);
@@ -1213,9 +1240,9 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
- IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+ IO.mapOptional("BinPackArguments", Style.PackArguments.BinPack);
IO.mapOptional("BinPackLongBracedList", Style.BinPackLongBracedList);
- IO.mapOptional("BinPackParameters", Style.BinPackParameters);
+ IO.mapOptional("BinPackParameters", Style.PackParameters.BinPack);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
Style.BracedInitializerIndentWidth);
@@ -1334,8 +1361,10 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("ObjCSpaceBeforeProtocolList",
Style.ObjCSpaceBeforeProtocolList);
IO.mapOptional("OneLineFormatOffRegex", Style.OneLineFormatOffRegex);
+ IO.mapOptional("PackArguments", Style.PackArguments);
IO.mapOptional("PackConstructorInitializers",
Style.PackConstructorInitializers);
+ IO.mapOptional("PackParameters", Style.PackParameters);
IO.mapOptional("PenaltyBreakAssignment", Style.PenaltyBreakAssignment);
IO.mapOptional("PenaltyBreakBeforeFirstCallParameter",
Style.PenaltyBreakBeforeFirstCallParameter);
@@ -1440,7 +1469,6 @@ template <> struct MappingTraits<FormatStyle> {
Style.WhitespaceSensitiveMacros);
IO.mapOptional("WrapNamespaceBodyWithEmptyLines",
Style.WrapNamespaceBodyWithEmptyLines);
- IO.mapOptional("BreakParametersAfter", Style.BreakParametersAfter);
// If AlwaysBreakAfterDefinitionReturnType was specified but
// BreakAfterReturnType was not, initialize the latter from the former for
@@ -1782,9 +1810,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AttributeMacros.push_back("__capability");
- LLVMStyle.BinPackArguments = true;
LLVMStyle.BinPackLongBracedList = true;
- LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack;
LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both;
LLVMStyle.BracedInitializerIndentWidth = -1;
LLVMStyle.BraceWrapping = {/*AfterCaseLabel=*/false,
@@ -1830,7 +1856,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
LLVMStyle.BreakFunctionDefinitionParameters = false;
LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
- LLVMStyle.BreakParametersAfter = 0;
LLVMStyle.BreakStringLiterals = true;
LLVMStyle.BreakTemplateDeclarations = FormatStyle::BTDS_MultiLine;
LLVMStyle.ColumnLimit = 80;
@@ -1894,7 +1919,11 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.ObjCSpaceAfterMethodDeclarationPrefix = true;
LLVMStyle.ObjCSpaceAfterProperty = false;
LLVMStyle.ObjCSpaceBeforeProtocolList = true;
+ LLVMStyle.PackArguments = {/*BinPack=*/FormatStyle::BPAS_BinPack,
+ /*BreakAfter=*/0};
LLVMStyle.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
+ LLVMStyle.PackParameters = {/*BinPack=*/FormatStyle::BPPS_BinPack,
+ /*BreakAfter=*/0};
LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
LLVMStyle.PPIndentWidth = -1;
LLVMStyle.QualifierAlignment = FormatStyle::QAS_Leave;
@@ -2192,7 +2221,7 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) {
FormatStyle::ShortFunctionStyle::setEmptyAndInline();
ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
ChromiumStyle.AllowShortLoopsOnASingleLine = false;
- ChromiumStyle.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ ChromiumStyle.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
ChromiumStyle.DerivePointerAlignment = false;
if (Language == FormatStyle::LK_ObjC)
ChromiumStyle.ColumnLimit = 80;
@@ -2207,8 +2236,8 @@ FormatStyle getMozillaStyle() {
FormatStyle::ShortFunctionStyle::setEmptyAndInline();
MozillaStyle.AlwaysBreakAfterDefinitionReturnType =
FormatStyle::DRTBS_TopLevel;
- MozillaStyle.BinPackArguments = false;
- MozillaStyle.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ MozillaStyle.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
+ MozillaStyle.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
MozillaStyle.BreakAfterReturnType = FormatStyle::RTBS_TopLevel;
MozillaStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
MozillaStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
@@ -2469,7 +2498,8 @@ std::error_code parseConfiguration(llvm::MemoryBufferRef Config,
}
if (Style->InsertTrailingCommas != FormatStyle::TCS_None &&
- Style->BinPackArguments) {
+ (Style->PackArguments.BinPack == FormatStyle::BPAS_BinPack ||
+ Style->PackArguments.BinPack == FormatStyle::BPAS_UseBreakAfter)) {
// See comment on FormatStyle::TSC_Wrapped.
return make_error_code(ParseError::BinPackTrailingCommaConflict);
}
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 28fdbcbf0e47f..7696ed3d33b5d 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -186,7 +186,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
// have many items (20 or more) or we allow bin-packing of function call
// arguments.
if (Style.Cpp11BracedListStyle != FormatStyle::BLS_Block &&
- !Style.BinPackArguments &&
+ Style.PackArguments.BinPack == FormatStyle::BPAS_OnePerLine &&
(Commas.size() < 19 || !Style.BinPackLongBracedList)) {
return;
}
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index fa190c535c576..898759cb8ea1b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4262,8 +4262,14 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
ChildSize + Current->SpacesRequiredBefore;
}
- if (Style.BreakParametersAfter > 0 && Prev->is(tok::l_paren) &&
- Prev->ParameterCount > Style.BreakParametersAfter) {
+ if ((Style.PackParameters.BinPack == FormatStyle::BPPS_UseBreakAfter &&
+ Prev->MightBeFunctionDeclParen &&
+ Prev->ParameterCount > Style.PackParameters.BreakAfter) ||
+ (Style.PackArguments.BinPack == FormatStyle::BPAS_UseBreakAfter &&
+ !Prev->MightBeFunctionDeclParen &&
+ Prev->isOneOf(tok::l_paren, tok::l_brace,
+ TT_ArrayInitializerLSquare) &&
+ Prev->ParameterCount > Style.PackArguments.BreakAfter)) {
const auto *RParen = Prev->MatchingParen;
for (auto *ParamTok = Current; ParamTok && ParamTok != RParen;
ParamTok = ParamTok->Next) {
@@ -5760,7 +5766,7 @@ bool TokenAnnotator::mustBreakBefore(AnnotatedLine &Line,
// Ignores the first parameter as this will be handled separately by
// BreakFunctionDefinitionParameters or AlignAfterOpenBracket.
- if (Style.BinPackParameters == FormatStyle::BPPS_AlwaysOnePerLine &&
+ if (Style.PackParameters.BinPack == FormatStyle::BPPS_AlwaysOnePerLine &&
Line.MightBeFunctionDecl && !Left.opensScope() &&
startsNextParameter(Right, Style)) {
return true;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 405ce9f4c3e23..f0c6539776ece 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8159,88 +8159,28 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
verifyFormat("void functionDecl(paramA, paramB);\n"
"void functionDecl(paramA,\n"
" paramB,\n"
- " paramC);\n"
- "void functionDecl(paramA,\n"
- " paramB,\n"
- " paramC,\n"
- " paramD,\n"
- " paramE);\n"
- "void functionDefinition(int A, int B) {}\n"
- "void functionDefinition(int A,\n"
- " int B,\n"
- " int C) {}\n"
- "Class::Class(int A, int B) {}\n"
- "Class::Class(int A,\n"
- " int B,\n"
- " int C) {}\n"
- "call(a, b);\n"
- "call(a,\n"
- " b,\n"
- " c);\n"
- "new Class(a, b);\n"
- "new Class(a,\n"
- " b,\n"
- " c);\n"
- "int x = (a, b);\n"
- "int y = (a,\n"
- " b,\n"
- " c);\n"
- "(a, b);\n"
- "(a,\n"
- " b,\n"
- " c);",
- Style);
- Style.BreakParametersAfter = 4;
- verifyFormat("void functionDecl(paramA);\n"
- "void functionDecl(paramA, paramB);\n"
- "void functionDecl(paramA, paramB, paramC);\n"
- "void functionDecl(paramA, paramB, paramC, paramD);\n"
- "void functionDecl(paramA,\n"
- " paramB,\n"
- " paramC,\n"
- " paramD,\n"
- " paramE);\n"
- "void functionDecl(paramA,\n"
- " paramB,\n"
- " paramC,\n"
- " paramD,\n"
- " paramE,\n"
- " paramF);\n"
- "void functionDefinition(int A, int B, int C, int D) {}\n"
+ " paramC);",
+ Style);
+ verifyFormat("void functionDefinition(int A, int B) {}\n"
"void functionDefinition(int A,\n"
" int B,\n"
- " int C,\n"
- " int D,\n"
- " int E) {}\n"
- "Class::Class(int A, int B) {}\n"
- "Class::Class(int A, int B, int C, int D) {}\n"
+ " int C) {}",
+ Style);
+ verifyFormat("Class::Class(int A, int B) {}\n"
"Class::Class(int A,\n"
" int B,\n"
- " int C,\n"
- " int D,\n"
- " int E) {}\n"
+ " int C) {}",
+ Style);
+ verifyFormat("call(a, b);\n"
"call(a,\n"
" b,\n"
- " c,\n"
- " d,\n"
- " e);\n"
+ " c);",
+ Style);
+ verifyFormat("new Class(a, b);\n"
"new Class(a,\n"
" b,\n"
- " c,\n"
- " d,\n"
- " e);\n"
- "int y = (a,\n"
- " b,\n"
- " c,\n"
- " d,\n"
- " e);\n"
- "(a,\n"
- " b,\n"
- " c,\n"
- " d,\n"
- " e);",
- Style);
- Style.BreakParametersAfter = 0;
+ " c);",
+ Style);
}
TEST_F(FormatTest, BreakBeforeInlineASMColon) {
>From ddba2f8f21514c0bc388e14d94e62bd781a43653 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Sat, 7 Mar 2026 20:59:51 -0500
Subject: [PATCH 09/13] Update unit tests
---
clang/unittests/Format/AlignBracketsTest.cpp | 26 +++---
clang/unittests/Format/AlignmentTest.cpp | 10 +--
clang/unittests/Format/ConfigParseTest.cpp | 51 +++++++----
clang/unittests/Format/FormatTest.cpp | 84 ++++++++++---------
clang/unittests/Format/FormatTestComments.cpp | 8 +-
clang/unittests/Format/FormatTestObjC.cpp | 4 +-
6 files changed, 106 insertions(+), 77 deletions(-)
diff --git a/clang/unittests/Format/AlignBracketsTest.cpp b/clang/unittests/Format/AlignBracketsTest.cpp
index 10ca5fb7da1ce..d61ce1eb4ea01 100644
--- a/clang/unittests/Format/AlignBracketsTest.cpp
+++ b/clang/unittests/Format/AlignBracketsTest.cpp
@@ -65,8 +65,8 @@ TEST_F(AlignBracketsTest, AlignsAfterOpenBracket) {
Style.ColumnLimit = 80;
Style.BreakAfterOpenBracketFunction = true;
- Style.BinPackArguments = false;
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaa aaaaaaaa,\n"
" aaaaaaaaa aaaaaaa,\n"
@@ -118,8 +118,8 @@ TEST_F(AlignBracketsTest, AlignsAfterOpenBracket) {
Style.BreakAfterOpenBracketFunction = true;
Style.BreakBeforeCloseBracketFunction = true;
Style.BreakBeforeCloseBracketBracedList = true;
- Style.BinPackArguments = false;
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaa aaaaaaaa,\n"
" aaaaaaaaa aaaaaaa,\n"
@@ -286,8 +286,8 @@ TEST_F(AlignBracketsTest, AlignAfterOpenBracketBlockIndent) {
");",
Medium, Style);
- Style.BinPackArguments = false;
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat(Short, Style);
@@ -676,7 +676,7 @@ TEST_F(AlignBracketsTest, AllowAllArgumentsOnNextLineDontAlign) {
TEST_F(AlignBracketsTest, FormatsDeclarationBreakAlways) {
FormatStyle BreakAlways = getGoogleStyle();
- BreakAlways.BinPackParameters = FormatStyle::BPPS_AlwaysOnePerLine;
+ BreakAlways.PackParameters.BinPack = FormatStyle::BPPS_AlwaysOnePerLine;
verifyFormat("void f(int a,\n"
" int b);",
BreakAlways);
@@ -685,7 +685,7 @@ TEST_F(AlignBracketsTest, FormatsDeclarationBreakAlways) {
" int cccccccccccccccccccccccc);",
BreakAlways);
- // Ensure AlignAfterOpenBracket interacts correctly with BinPackParameters set
+ // Ensure AlignAfterOpenBracket interacts correctly with PackParameters.BinPack set
// to BPPS_AlwaysOnePerLine.
BreakAlways.BreakAfterOpenBracketFunction = true;
verifyFormat(
@@ -705,14 +705,14 @@ TEST_F(AlignBracketsTest, FormatsDeclarationBreakAlways) {
TEST_F(AlignBracketsTest, FormatsDefinitionBreakAlways) {
FormatStyle BreakAlways = getGoogleStyle();
- BreakAlways.BinPackParameters = FormatStyle::BPPS_AlwaysOnePerLine;
+ BreakAlways.PackParameters.BinPack = FormatStyle::BPPS_AlwaysOnePerLine;
verifyFormat("void f(int a,\n"
" int b) {\n"
" f(a, b);\n"
"}",
BreakAlways);
- // Ensure BinPackArguments interact correctly when BinPackParameters is set to
+ // Ensure BinPackArguments interact correctly when PackParameters.BinPack is set to
// BPPS_AlwaysOnePerLine.
verifyFormat("void f(int aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" int bbbbbbbbbbbbbbbbbbbbbbbbb,\n"
@@ -721,7 +721,7 @@ TEST_F(AlignBracketsTest, FormatsDefinitionBreakAlways) {
" cccccccccccccccccccccccc);\n"
"}",
BreakAlways);
- BreakAlways.BinPackArguments = false;
+ BreakAlways.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
verifyFormat("void f(int aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" int bbbbbbbbbbbbbbbbbbbbbbbbb,\n"
" int cccccccccccccccccccccccc) {\n"
@@ -732,7 +732,7 @@ TEST_F(AlignBracketsTest, FormatsDefinitionBreakAlways) {
BreakAlways);
// Ensure BreakFunctionDefinitionParameters interacts correctly when
- // BinPackParameters is set to BPPS_AlwaysOnePerLine.
+ // PackParameters.BinPack is set to BPPS_AlwaysOnePerLine.
BreakAlways.BreakFunctionDefinitionParameters = true;
verifyFormat("void f(\n"
" int a,\n"
@@ -742,7 +742,7 @@ TEST_F(AlignBracketsTest, FormatsDefinitionBreakAlways) {
BreakAlways);
BreakAlways.BreakFunctionDefinitionParameters = false;
- // Ensure AlignAfterOpenBracket interacts correctly with BinPackParameters set
+ // Ensure AlignAfterOpenBracket interacts correctly with PackParameters.BinPack set
// to BPPS_AlwaysOnePerLine.
BreakAlways.BreakAfterOpenBracketFunction = true;
verifyFormat(
diff --git a/clang/unittests/Format/AlignmentTest.cpp b/clang/unittests/Format/AlignmentTest.cpp
index e3a3435424914..526cedfd81836 100644
--- a/clang/unittests/Format/AlignmentTest.cpp
+++ b/clang/unittests/Format/AlignmentTest.cpp
@@ -613,7 +613,7 @@ TEST_F(AlignmentTest, ConsecutiveAssignments) {
// See https://llvm.org/PR55360
Alignment = getLLVMStyleWithColumns(50);
Alignment.AlignConsecutiveAssignments.Enabled = true;
- Alignment.BinPackArguments = false;
+ Alignment.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
verifyFormat("int a_long_name = 1;\n"
"auto b = B({a_long_name, a_long_name},\n"
" {a_longer_name_for_wrap,\n"
@@ -1596,7 +1596,7 @@ TEST_F(AlignmentTest, ConsecutiveDeclarations) {
auto Style = AlignmentLeft;
Style.AlignConsecutiveDeclarations.AlignFunctionPointers = true;
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("int function_name(const wchar_t* title,\n"
" int x = 0,\n"
" long extraStyle = 0,\n"
@@ -1804,7 +1804,7 @@ TEST_F(AlignmentTest, ConsecutiveDeclarations) {
Alignment.AlignConsecutiveAssignments.Enabled = false;
Alignment.ColumnLimit = 30;
- Alignment.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Alignment.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("void foo(float a,\n"
" float b,\n"
" int c,\n"
@@ -1818,7 +1818,7 @@ TEST_F(AlignmentTest, ConsecutiveDeclarations) {
" uint32_t *c,\n"
" bool d) {}",
Alignment);
- Alignment.BinPackParameters = FormatStyle::BPPS_BinPack;
+ Alignment.PackParameters.BinPack = FormatStyle::BPPS_BinPack;
Alignment.ColumnLimit = 80;
// Bug 33507
@@ -2555,7 +2555,7 @@ TEST_F(AlignmentTest, AlignWithLineBreaks) {
Style);
// clang-format on
- Style.BinPackArguments = false;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
// clang-format off
verifyFormat("void SomeFunc() {\n"
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index f56e143d60a42..4e41684a1c3e1 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -168,7 +168,6 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortNamespacesOnASingleLine);
- CHECK_PARSE_BOOL(BinPackArguments);
CHECK_PARSE_BOOL(BinPackLongBracedList);
CHECK_PARSE_BOOL(BreakAdjacentStringLiterals);
CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
@@ -286,7 +285,6 @@ TEST(ConfigParseTest, ParsesConfigurationIntegers) {
CHECK_PARSE_INT(BracedInitializerIndentWidth);
CHECK_PARSE_INT(PPIndentWidth);
- CHECK_PARSE_UNSIGNED(BreakParametersAfter);
CHECK_PARSE_UNSIGNED(ColumnLimit);
CHECK_PARSE_UNSIGNED(ConstructorInitializerIndentWidth);
CHECK_PARSE_UNSIGNED(ContinuationIndentWidth);
@@ -535,19 +533,23 @@ TEST(ConfigParseTest, ParsesConfiguration) {
CHECK_PARSE("BreakBeforeInheritanceComma: true", BreakInheritanceList,
FormatStyle::BILS_BeforeComma);
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
- CHECK_PARSE("BinPackParameters: BinPack", BinPackParameters,
- FormatStyle::BPPS_BinPack);
- CHECK_PARSE("BinPackParameters: OnePerLine", BinPackParameters,
- FormatStyle::BPPS_OnePerLine);
- CHECK_PARSE("BinPackParameters: AlwaysOnePerLine", BinPackParameters,
- FormatStyle::BPPS_AlwaysOnePerLine);
- // For backward compatibility.
- CHECK_PARSE("BinPackParameters: true", BinPackParameters,
- FormatStyle::BPPS_BinPack);
- CHECK_PARSE("BinPackParameters: false", BinPackParameters,
- FormatStyle::BPPS_OnePerLine);
-
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
+ CHECK_PARSE_NESTED_VALUE("BinPack: BinPack", PackArguments, BinPack,
+ FormatStyle::BPAS_BinPack);
+ CHECK_PARSE_NESTED_VALUE("BinPack: OnePerLine", PackArguments, BinPack,
+ FormatStyle::BPAS_OnePerLine);
+ CHECK_PARSE_NESTED_VALUE("BinPack: UseBreakAfter", PackArguments, BinPack,
+ FormatStyle::BPAS_UseBreakAfter);
+ CHECK_PARSE_NESTED_VALUE("BreakAfter: 1234", PackArguments,
+ BreakAfter, 1234u);
+ // For backward compatibility:
+ CHECK_PARSE_NESTED_VALUE("BinPack: true", PackArguments, BinPack,
+ FormatStyle::BPAS_BinPack);
+ CHECK_PARSE_NESTED_VALUE("BinPack: false", PackArguments, BinPack,
+ FormatStyle::BPAS_OnePerLine);
+ CHECK_PARSE("BinPackArguments: true", PackArguments.BinPack,
+ FormatStyle::BPAS_BinPack);
+
Style.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
CHECK_PARSE("PackConstructorInitializers: Never", PackConstructorInitializers,
FormatStyle::PCIS_Never);
@@ -576,6 +578,25 @@ TEST(ConfigParseTest, ParsesConfiguration) {
"AllowAllConstructorInitializersOnNextLine: false",
PackConstructorInitializers, FormatStyle::PCIS_CurrentLine);
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
+ CHECK_PARSE_NESTED_VALUE("BinPack: BinPack", PackParameters, BinPack,
+ FormatStyle::BPPS_BinPack);
+ CHECK_PARSE_NESTED_VALUE("BinPack: OnePerLine", PackParameters, BinPack,
+ FormatStyle::BPPS_OnePerLine);
+ CHECK_PARSE_NESTED_VALUE("BinPack: AlwaysOnePerLine", PackParameters, BinPack,
+ FormatStyle::BPPS_AlwaysOnePerLine);
+ CHECK_PARSE_NESTED_VALUE("BinPack: UseBreakAfter", PackParameters, BinPack,
+ FormatStyle::BPPS_UseBreakAfter);
+ CHECK_PARSE_NESTED_VALUE("BreakAfter: 1234", PackParameters,
+ BreakAfter, 1234u);
+ // For backward compatibility:
+ CHECK_PARSE_NESTED_VALUE("BinPack: true", PackParameters, BinPack,
+ FormatStyle::BPPS_BinPack);
+ CHECK_PARSE_NESTED_VALUE("BinPack: false", PackParameters, BinPack,
+ FormatStyle::BPPS_OnePerLine);
+ CHECK_PARSE("BinPackParameters: BinPack", PackParameters.BinPack,
+ FormatStyle::BPPS_BinPack);
+
Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
CHECK_PARSE("EmptyLineBeforeAccessModifier: Never",
EmptyLineBeforeAccessModifier, FormatStyle::ELBAMS_Never);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index f0c6539776ece..40711976ff87d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2362,7 +2362,7 @@ TEST_F(FormatTest, FormatsForLoop) {
"for (const Foo<Bar> &baz = in.value(); !baz.at_end(); ++baz) {\n}");
FormatStyle NoBinPacking = getLLVMStyle();
- NoBinPacking.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ NoBinPacking.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("for (int aaaaaaaaaaa = 1;\n"
" aaaaaaaaaaa <= aaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaa,\n"
@@ -5250,7 +5250,7 @@ TEST_F(FormatTest, DesignatedInitializers) {
TEST_F(FormatTest, BracedInitializerIndentWidth) {
auto Style = getLLVMStyleWithColumns(60);
- Style.BinPackArguments = true;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_BinPack;
Style.BreakAfterOpenBracketFunction = true;
Style.BreakAfterOpenBracketBracedList = true;
Style.BracedInitializerIndentWidth = 6;
@@ -7307,7 +7307,7 @@ TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
"}");
FormatStyle OnePerLine = getLLVMStyle();
- OnePerLine.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ OnePerLine.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat(
"if (aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
@@ -7461,7 +7461,7 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) {
Style = getLLVMStyleWithColumns(20);
Style.BreakAfterOpenBracketFunction = true;
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
Style.ContinuationIndentWidth = 2;
verifyFormat("struct Foo {\n"
@@ -7642,7 +7642,7 @@ TEST_F(FormatTest, BreakingBeforeNonAssignmentOperators) {
TEST_F(FormatTest, AllowBinPackingInsideArguments) {
FormatStyle Style = getLLVMStyleWithColumns(40);
Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
- Style.BinPackArguments = false;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
verifyFormat("void test() {\n"
" someFunction(\n"
" this + argument + is + quite\n"
@@ -7836,7 +7836,7 @@ TEST_F(FormatTest, ConstructorInitializers) {
" : aaaaa(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaa) {}",
OnePerLine);
- OnePerLine.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ OnePerLine.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat(
"Constructor()\n"
" : aaaaaaaaaaaaaaaaaaaaaaaa(\n"
@@ -7870,7 +7870,7 @@ TEST_F(FormatTest, ConstructorInitializers) {
TEST_F(FormatTest, AllowAllConstructorInitializersOnNextLine) {
FormatStyle Style = getLLVMStyleWithColumns(60);
Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
for (int i = 0; i < 4; ++i) {
// Test all combinations of parameters that should not have an effect.
@@ -8069,7 +8069,7 @@ TEST_F(FormatTest, AllowAllConstructorInitializersOnNextLine) {
TEST_F(FormatTest, AllowAllArgumentsOnNextLine) {
FormatStyle Style = getLLVMStyleWithColumns(60);
- Style.BinPackArguments = false;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
for (int i = 0; i < 4; ++i) {
// Test all combinations of parameters that should not have an effect.
Style.AllowAllParametersOfDeclarationOnNextLine = i & 1;
@@ -8106,7 +8106,7 @@ TEST_F(FormatTest, AllowAllArgumentsOnNextLine) {
}
// This parameter should not affect declarations.
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
Style.AllowAllArgumentsOnNextLine = false;
Style.AllowAllParametersOfDeclarationOnNextLine = true;
verifyFormat("void FunctionCallWithReallyLongName(\n"
@@ -8140,7 +8140,7 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
// Test the style where all parameters are on their own lines.
Style.AllowAllParametersOfDeclarationOnNextLine = false;
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("void functionDecl(paramA, paramB, paramC);\n"
"void emptyFunctionDefinition() {}\n"
"void functionDefinition(\n"
@@ -8153,9 +8153,9 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
" : m_A(A), m_B(B) {}",
Input, Style);
- Style.BinPackParameters = FormatStyle::BPPS_BinPack;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_UseBreakAfter;
Style.BreakFunctionDefinitionParameters = false;
- Style.BreakParametersAfter = 2;
+ Style.PackParameters.BreakAfter = 2;
verifyFormat("void functionDecl(paramA, paramB);\n"
"void functionDecl(paramA,\n"
" paramB,\n"
@@ -8171,15 +8171,23 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
" int B,\n"
" int C) {}",
Style);
- verifyFormat("call(a, b);\n"
- "call(a,\n"
- " b,\n"
- " c);",
+
+ Style.PackParameters.BinPack = FormatStyle::BPPS_BinPack;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_UseBreakAfter;
+ Style.PackArguments.BreakAfter = 2;
+ verifyFormat("void foo() {\n"
+ " call(a, b);\n"
+ " call(a,\n"
+ " b,\n"
+ " c);\n"
+ "}",
Style);
- verifyFormat("new Class(a, b);\n"
- "new Class(a,\n"
- " b,\n"
- " c);",
+ verifyFormat("void foo() {\n"
+ " new Class(a, b);\n"
+ " new Class(a,\n"
+ " b,\n"
+ " c);\n"
+ "}",
Style);
}
@@ -8364,7 +8372,7 @@ TEST_F(FormatTest, BreakConstructorInitializersAfterColon) {
" aaaaa(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaa) {}",
OnePerLine);
- OnePerLine.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ OnePerLine.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("Constructor() :\n"
" aaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaa().aaa(),\n"
@@ -8633,7 +8641,7 @@ TEST_F(FormatTest, MemoizationTests) {
// This test takes VERY long when memoization is broken.
FormatStyle OnePerLine = getLLVMStyle();
OnePerLine.PackConstructorInitializers = FormatStyle::PCIS_NextLine;
- OnePerLine.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ OnePerLine.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
std::string input = "Constructor()\n"
" : aaaa(a,\n";
for (unsigned i = 0, e = 80; i != e; ++i)
@@ -9066,8 +9074,8 @@ TEST_F(FormatTest, BreaksDesireably) {
TEST_F(FormatTest, FormatsDeclarationsOnePerLine) {
FormatStyle NoBinPacking = getGoogleStyle();
- NoBinPacking.BinPackParameters = FormatStyle::BPPS_OnePerLine;
- NoBinPacking.BinPackArguments = true;
+ NoBinPacking.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
+ NoBinPacking.PackArguments.BinPack = FormatStyle::BPAS_BinPack;
verifyFormat("void f() {\n"
" f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);\n"
@@ -9098,8 +9106,8 @@ TEST_F(FormatTest, FormatsDeclarationsOnePerLine) {
TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {
FormatStyle NoBinPacking = getGoogleStyle();
- NoBinPacking.BinPackParameters = FormatStyle::BPPS_OnePerLine;
- NoBinPacking.BinPackArguments = false;
+ NoBinPacking.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
+ NoBinPacking.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
verifyFormat("f(aaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaa);",
@@ -9650,7 +9658,7 @@ TEST_F(FormatTest, BreaksConditionalExpressions) {
" : aaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
FormatStyle NoBinPacking = getLLVMStyle();
- NoBinPacking.BinPackArguments = false;
+ NoBinPacking.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
verifyFormat(
"void f() {\n"
" g(aaa,\n"
@@ -10867,7 +10875,7 @@ TEST_F(FormatTest, WrapsAtFunctionCallsIfNecessary) {
" .a();");
FormatStyle NoBinPacking = getLLVMStyle();
- NoBinPacking.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ NoBinPacking.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("aaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)\n"
" .aaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaa)\n"
" .aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaa,\n"
@@ -14061,7 +14069,7 @@ TEST_F(FormatTest, HandlesIncludeDirectives) {
TEST_F(FormatTest, IncompleteParameterLists) {
FormatStyle NoBinPacking = getLLVMStyle();
- NoBinPacking.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ NoBinPacking.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("void aaaaaaaaaaaaaaaaaa(int level,\n"
" double *min_x,\n"
" double *max_x,\n"
@@ -14336,9 +14344,9 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
"}\n"
"SomeType t;");
- // In combination with BinPackArguments = false.
+ // In combination with PackArguments.BinPack = FormatStyle::BPAS_OnePerLine.
FormatStyle NoBinPacking = getLLVMStyle();
- NoBinPacking.BinPackArguments = false;
+ NoBinPacking.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
verifyFormat("const Aaaaaa aaaaa = {aaaaa,\n"
" bbbbb,\n"
" ccccc,\n"
@@ -14774,7 +14782,7 @@ TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
" [](const Input &i) -> Output { return "
"Output{1, 2}; });");
FormatStyle NoBinPacking = getLLVMStyle();
- NoBinPacking.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ NoBinPacking.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("waarudo::unit desk = {\n"
" .s = \"desk\", .p = p, .b = [] { return w::r{3, 10, 1, 1, "
"1, 1} * w::m; }};",
@@ -20791,7 +20799,7 @@ TEST_F(FormatTest, FormatsLambdas) {
// A multi-line lambda passed as arg1 forces arg0 to be pushed out, just like
// the arg0 case above.
auto Style = getGoogleStyle();
- Style.BinPackArguments = false;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
verifyFormat("SomeFunction(\n"
" a,\n"
" [this] {\n"
@@ -21109,7 +21117,7 @@ TEST_F(FormatTest, FormatsLambdas) {
" LambdaBodyMustBeBreak);\n"
"};",
LLVMWithBeforeLambdaBody);
- LLVMWithBeforeLambdaBody.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ LLVMWithBeforeLambdaBody.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("FctAllOnSameLine_SLS_All([]() { return S; }, Fst, Second);",
LLVMWithBeforeLambdaBody);
verifyFormat(
@@ -21404,7 +21412,7 @@ TEST_F(FormatTest, FormatsLambdas) {
" quuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuux);\n"
"}",
Style);
- Style.BinPackArguments = false;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
verifyFormat("void foo() {\n"
" aFunction(\n"
" 1,\n"
@@ -21422,7 +21430,7 @@ TEST_F(FormatTest, FormatsLambdas) {
" quuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuux);\n"
"}",
Style);
- Style.BinPackArguments = true;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_BinPack;
Style.BreakBeforeBraces = FormatStyle::BS_Custom;
Style.BraceWrapping.BeforeLambdaBody = true;
verifyFormat("void foo() {\n"
@@ -26243,11 +26251,11 @@ TEST_F(FormatTest, KeywordedFunctionLikeMacros) {
auto Style = getLLVMStyle();
Style.AllowBreakBeforeQtProperty = true;
- Style.BinPackParameters = FormatStyle::BPPS_AlwaysOnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_AlwaysOnePerLine;
verifyFormat(Code, Style);
verifyFormat(Code2, Style);
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
Style.ColumnLimit = 40;
verifyFormat(Code, Style);
verifyFormat(Code2, Style);
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp
index 684d3014fa7bb..7ae9da526660f 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -349,7 +349,7 @@ TEST_F(FormatTestComments, KeepsParameterWithTrailingCommentsOnTheirOwnLine) {
"aaaa, bbbbb);");
FormatStyle BreakAlways = getLLVMStyle();
- BreakAlways.BinPackParameters = FormatStyle::BPPS_AlwaysOnePerLine;
+ BreakAlways.PackParameters.BinPack = FormatStyle::BPPS_AlwaysOnePerLine;
verifyFormat("int SomeFunction(a,\n"
" b, // comment\n"
" c,\n"
@@ -405,7 +405,7 @@ TEST_F(FormatTestComments, UnderstandsBlockComments) {
" /* 3rd */ int dddddddddddd);");
auto Style = getLLVMStyle();
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("aaaaaaaa(/* parameter 1 */ aaaaaa,\n"
" /* parameter 2 */ aaaaaa,\n"
" /* parameter 3 */ aaaaaa,\n"
@@ -417,7 +417,7 @@ TEST_F(FormatTestComments, UnderstandsBlockComments) {
" /* 3rd */ int dddddddddddd);",
Style);
- Style.BinPackParameters = FormatStyle::BPPS_AlwaysOnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_AlwaysOnePerLine;
verifyFormat("int a(/* 1st */ int b,\n"
" /* 2nd */ int c);",
Style);
@@ -2444,7 +2444,7 @@ TEST_F(FormatTestComments, BlockComments) {
getLLVMStyleWithColumns(50));
FormatStyle NoBinPacking = getLLVMStyle();
- NoBinPacking.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ NoBinPacking.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
verifyFormat("someFunction(1, /* comment 1 */\n"
" 2, /* comment 2 */\n"
" 3, /* comment 3 */\n"
diff --git a/clang/unittests/Format/FormatTestObjC.cpp b/clang/unittests/Format/FormatTestObjC.cpp
index c685c5554f9b5..09a9687d6f87a 100644
--- a/clang/unittests/Format/FormatTestObjC.cpp
+++ b/clang/unittests/Format/FormatTestObjC.cpp
@@ -377,7 +377,7 @@ TEST_F(FormatTestObjC, FormatObjCInterface) {
" ddddddddddddd> {\n"
"}");
- Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ Style.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
Style.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
verifyFormat("@interface eeeeeeeeeeeee () <\n"
" eeeeeeeeeeeee,\n"
@@ -411,7 +411,7 @@ TEST_F(FormatTestObjC, FormatObjCInterface) {
"+ (id)init;\n"
"@end");
Style.ColumnLimit = 40;
- // BinPackParameters should be BPPS_BinPack by default.
+ // PackParameters.BinPack should be BPPS_BinPack by default.
verifyFormat("void eeeeeeee(int eeeee, int eeeee,\n"
" int eeeee, int eeeee);");
// ObjCBinPackProtocolList should be BPS_Never by default.
>From 82fc3adec4708357571636f78396b6dcfef4f574 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Sat, 7 Mar 2026 21:34:07 -0500
Subject: [PATCH 10/13] Add unit tests for nested calls
---
clang/unittests/Format/FormatTest.cpp | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 40711976ff87d..1664d3b9915ce 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8180,6 +8180,18 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
" call(a,\n"
" b,\n"
" c);\n"
+ " call(a, inner(a, b));\n"
+ " call(a,\n"
+ " inner(a, b),\n"
+ " b);\n"
+ " call(a, inner(a,\n"
+ " b,\n"
+ " c));\n"
+ " call(a,\n"
+ " inner(a,\n"
+ " b,\n"
+ " c),\n"
+ " b);\n"
"}",
Style);
verifyFormat("void foo() {\n"
>From 4aa4dcc3a2607aa3548e9aee18ab7d4c7794d17d Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Sat, 7 Mar 2026 21:45:41 -0500
Subject: [PATCH 11/13] Add unit tests for braced initializer lists
---
clang/unittests/Format/FormatTest.cpp | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 1664d3b9915ce..35a8d9f99e357 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8199,6 +8199,10 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
" new Class(a,\n"
" b,\n"
" c);\n"
+ " int nums[]{1, 2};\n"
+ " int nums[]{1,\n"
+ " 2,\n"
+ " 3};\n"
"}",
Style);
}
>From 2eccb101eef2b2dfe8037247259344b339142528 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Thu, 19 Mar 2026 12:08:54 -0400
Subject: [PATCH 12/13] Properly deprecate old options, add unit tests, update
release notes
---
clang/docs/ClangFormatStyleOptions.rst | 47 ++++++++++++++++++++++
clang/docs/ReleaseNotes.rst | 5 +++
clang/include/clang/Format/Format.h | 8 ++++
clang/lib/Format/Format.cpp | 4 +-
clang/unittests/Format/ConfigParseTest.cpp | 28 ++++++++++---
5 files changed, 85 insertions(+), 7 deletions(-)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 2375c0a376425..d31728e49ea4a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2247,6 +2247,11 @@ the configuration (without a prefix: ``Auto``).
AttributeMacros: [__capability, __output, __unused]
+.. _BinPackArguments:
+
+**BinPackArguments** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackArguments>`
+ This option is **deprecated**. See ``BinPack`` of ``PackArguments``.
+
.. _BinPackLongBracedList:
**BinPackLongBracedList** (``Boolean``) :versionbadge:`clang-format 21` :ref:`¶ <BinPackLongBracedList>`
@@ -2265,6 +2270,48 @@ the configuration (without a prefix: ``Auto``).
20,
21};
+.. _BinPackParameters:
+
+**BinPackParameters** (``BinPackParametersStyle``) :versionbadge:`clang-format 3.7` :ref:`¶ <BinPackParameters>`
+ This option is **deprecated**. See ``BinPack`` of ``PackParameters``.
+
+ Possible values:
+
+ * ``BPPS_BinPack`` (in configuration: ``BinPack``)
+ Bin-pack parameters.
+
+ .. code-block:: c++
+
+ void f(int a, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
+ int ccccccccccccccccccccccccccccccccccccccccccc);
+
+ * ``BPPS_OnePerLine`` (in configuration: ``OnePerLine``)
+ Put all parameters on the current line if they fit.
+ Otherwise, put each one on its own line.
+
+ .. code-block:: c++
+
+ void f(int a, int b, int c);
+
+ void f(int a,
+ int b,
+ int ccccccccccccccccccccccccccccccccccccc);
+
+ * ``BPPS_AlwaysOnePerLine`` (in configuration: ``AlwaysOnePerLine``)
+ Always put each parameter on its own line.
+
+ .. code-block:: c++
+
+ void f(int a,
+ int b,
+ int c);
+
+ * ``BPPS_UseBreakAfter`` (in configuration: ``UseBreakAfter``)
+ Use the ``BreakAfter`` option to handle parameter packing instead.
+ If the ``BreakAfter`` limit is not exceeded, behave like ``BinPack``.
+
+
+
.. _BitFieldColonSpacing:
**BitFieldColonSpacing** (``BitFieldColonSpacingStyle``) :versionbadge:`clang-format 12` :ref:`¶ <BitFieldColonSpacing>`
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fd58d7847717c..fc7f835de20d0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -577,6 +577,11 @@ clang-format
------------
- Add ``ObjCSpaceAfterMethodDeclarationPrefix`` option to control space between the
'-'/'+' and the return type in Objective-C method declarations
+- Deprecate the ``BinPackParameters`` and ``BinPackArguments`` options and replace
+ them with the ``PackParameters`` and ``PackArguments`` structs (respectively) to
+ unify packing behavior. Add the ``BreakAfter`` option to the structs, allowing
+ parameter and argument lists to be formatted with one parameter/argument on each
+ line if they exceed the specified count.
- Add ``AfterComma`` value to ``BreakConstructorInitializers`` to allow breaking
constructor initializers after commas, keeping the colon on the same line.
- Extend ``BreakBinaryOperations`` to accept a structured configuration with
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 4b45e2133c61b..bfaf95b02462b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1295,6 +1295,10 @@ struct FormatStyle {
/// \version 12
std::vector<std::string> AttributeMacros;
+ /// This option is **deprecated**. See ``BinPack`` of ``PackArguments``.
+ /// \version 3.7
+ // bool BinPackArguments;
+
/// If ``BinPackLongBracedList`` is ``true`` it overrides
/// ``BinPackArguments`` if there are 20 or more items in a braced
/// initializer list.
@@ -1311,6 +1315,10 @@ struct FormatStyle {
/// \version 21
bool BinPackLongBracedList;
+ /// This option is **deprecated**. See ``BinPack`` of ``PackParameters``.
+ /// \version 3.7
+ // BinPackParametersStyle BinPackParameters;
+
/// Styles for adding spacing around ``:`` in bitfield definitions.
enum BitFieldColonSpacingStyle : int8_t {
/// Add one space on each side of the ``:``
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c5fa12a78162f..4a1d6882c6ce4 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1158,6 +1158,8 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("AlwaysBreakAfterReturnType", Style.BreakAfterReturnType);
IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.BreakTemplateDeclarations);
+ IO.mapOptional("BinPackArguments", Style.PackArguments.BinPack);
+ IO.mapOptional("BinPackParameters", Style.PackParameters.BinPack);
IO.mapOptional("BreakBeforeInheritanceComma",
BreakBeforeInheritanceComma);
IO.mapOptional("BreakConstructorInitializersBeforeComma",
@@ -1240,9 +1242,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
- IO.mapOptional("BinPackArguments", Style.PackArguments.BinPack);
IO.mapOptional("BinPackLongBracedList", Style.BinPackLongBracedList);
- IO.mapOptional("BinPackParameters", Style.PackParameters.BinPack);
IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing);
IO.mapOptional("BracedInitializerIndentWidth",
Style.BracedInitializerIndentWidth);
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 4e41684a1c3e1..1ee4212390973 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -540,16 +540,22 @@ TEST(ConfigParseTest, ParsesConfiguration) {
FormatStyle::BPAS_OnePerLine);
CHECK_PARSE_NESTED_VALUE("BinPack: UseBreakAfter", PackArguments, BinPack,
FormatStyle::BPAS_UseBreakAfter);
- CHECK_PARSE_NESTED_VALUE("BreakAfter: 1234", PackArguments,
- BreakAfter, 1234u);
+ CHECK_PARSE_NESTED_VALUE("BreakAfter: 1234", PackArguments, BreakAfter,
+ 1234u);
// For backward compatibility:
+ CHECK_PARSE("PackArguments:\n"
+ " BinPack: OnePerLine\n"
+ "BinPackArguments: true",
+ PackArguments.BinPack, FormatStyle::BPAS_OnePerLine);
CHECK_PARSE_NESTED_VALUE("BinPack: true", PackArguments, BinPack,
FormatStyle::BPAS_BinPack);
CHECK_PARSE_NESTED_VALUE("BinPack: false", PackArguments, BinPack,
FormatStyle::BPAS_OnePerLine);
CHECK_PARSE("BinPackArguments: true", PackArguments.BinPack,
FormatStyle::BPAS_BinPack);
-
+ CHECK_PARSE("BinPackArguments: false", PackArguments.BinPack,
+ FormatStyle::BPAS_OnePerLine);
+
Style.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
CHECK_PARSE("PackConstructorInitializers: Never", PackConstructorInitializers,
FormatStyle::PCIS_Never);
@@ -587,15 +593,27 @@ TEST(ConfigParseTest, ParsesConfiguration) {
FormatStyle::BPPS_AlwaysOnePerLine);
CHECK_PARSE_NESTED_VALUE("BinPack: UseBreakAfter", PackParameters, BinPack,
FormatStyle::BPPS_UseBreakAfter);
- CHECK_PARSE_NESTED_VALUE("BreakAfter: 1234", PackParameters,
- BreakAfter, 1234u);
+ CHECK_PARSE_NESTED_VALUE("BreakAfter: 1234", PackParameters, BreakAfter,
+ 1234u);
// For backward compatibility:
+ CHECK_PARSE("PackParameters:\n"
+ " BinPack: OnePerLine\n"
+ "BinPackParameters: BinPack",
+ PackParameters.BinPack, FormatStyle::BPPS_OnePerLine);
CHECK_PARSE_NESTED_VALUE("BinPack: true", PackParameters, BinPack,
FormatStyle::BPPS_BinPack);
CHECK_PARSE_NESTED_VALUE("BinPack: false", PackParameters, BinPack,
FormatStyle::BPPS_OnePerLine);
CHECK_PARSE("BinPackParameters: BinPack", PackParameters.BinPack,
FormatStyle::BPPS_BinPack);
+ CHECK_PARSE("BinPackParameters: OnePerLine", PackParameters.BinPack,
+ FormatStyle::BPPS_OnePerLine);
+ CHECK_PARSE("BinPackParameters: AlwaysOnePerLine", PackParameters.BinPack,
+ FormatStyle::BPPS_AlwaysOnePerLine);
+ CHECK_PARSE("BinPackParameters: true", PackParameters.BinPack,
+ FormatStyle::BPPS_BinPack);
+ CHECK_PARSE("BinPackParameters: false", PackParameters.BinPack,
+ FormatStyle::BPPS_OnePerLine);
Style.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
CHECK_PARSE("EmptyLineBeforeAccessModifier: Never",
>From a397354147a0965faf4e2cc3aa30b69aef7c73f3 Mon Sep 17 00:00:00 2001
From: Ezlanding1 <113404035+Ezlanding1 at users.noreply.github.com>
Date: Sun, 19 Apr 2026 16:00:01 -0400
Subject: [PATCH 13/13] Fix formatting errors, update docs
---
clang/docs/ClangFormatStyleOptions.rst | 6 ++----
clang/unittests/Format/AlignBracketsTest.cpp | 12 ++++++------
clang/unittests/Format/FormatTest.cpp | 3 ++-
3 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index d31728e49ea4a..e35e5f8b9f9a9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5866,8 +5866,7 @@ the configuration (without a prefix: ``Auto``).
If the ``BreakAfter`` limit is not exceeded, behave like ``BinPack``.
- * ``unsigned BreakAfter`` :versionbadge:`clang-format 23`
- An argument list with more arguments than the specified number will be
+ * ``unsigned BreakAfter`` :versionbadge:`clang-format 23` An argument list with more arguments than the specified number will be
formatted with one argument per line. This option must be used with
``BinPack: UseBreakAfter``.
@@ -6013,8 +6012,7 @@ the configuration (without a prefix: ``Auto``).
If the ``BreakAfter`` limit is not exceeded, behave like ``BinPack``.
- * ``unsigned BreakAfter`` :versionbadge:`clang-format 23`
- A parameter list with more parameters than the specified number will be
+ * ``unsigned BreakAfter`` :versionbadge:`clang-format 23` A parameter list with more parameters than the specified number will be
formatted with one parameter per line. This option must be used with
``BinPack: UseBreakAfter``.
diff --git a/clang/unittests/Format/AlignBracketsTest.cpp b/clang/unittests/Format/AlignBracketsTest.cpp
index d61ce1eb4ea01..cd314305751e7 100644
--- a/clang/unittests/Format/AlignBracketsTest.cpp
+++ b/clang/unittests/Format/AlignBracketsTest.cpp
@@ -685,8 +685,8 @@ TEST_F(AlignBracketsTest, FormatsDeclarationBreakAlways) {
" int cccccccccccccccccccccccc);",
BreakAlways);
- // Ensure AlignAfterOpenBracket interacts correctly with PackParameters.BinPack set
- // to BPPS_AlwaysOnePerLine.
+ // Ensure AlignAfterOpenBracket interacts correctly with
+ // PackParameters.BinPack set to BPPS_AlwaysOnePerLine.
BreakAlways.BreakAfterOpenBracketFunction = true;
verifyFormat(
"void someLongFunctionName(\n"
@@ -712,8 +712,8 @@ TEST_F(AlignBracketsTest, FormatsDefinitionBreakAlways) {
"}",
BreakAlways);
- // Ensure BinPackArguments interact correctly when PackParameters.BinPack is set to
- // BPPS_AlwaysOnePerLine.
+ // Ensure BinPackArguments interact correctly when PackParameters.BinPack is
+ // set to BPPS_AlwaysOnePerLine.
verifyFormat("void f(int aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" int bbbbbbbbbbbbbbbbbbbbbbbbb,\n"
" int cccccccccccccccccccccccc) {\n"
@@ -742,8 +742,8 @@ TEST_F(AlignBracketsTest, FormatsDefinitionBreakAlways) {
BreakAlways);
BreakAlways.BreakFunctionDefinitionParameters = false;
- // Ensure AlignAfterOpenBracket interacts correctly with PackParameters.BinPack set
- // to BPPS_AlwaysOnePerLine.
+ // Ensure AlignAfterOpenBracket interacts correctly with
+ // PackParameters.BinPack set to BPPS_AlwaysOnePerLine.
BreakAlways.BreakAfterOpenBracketFunction = true;
verifyFormat(
"void someLongFunctionName(\n"
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 35a8d9f99e357..a24b3409dbe82 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21133,7 +21133,8 @@ TEST_F(FormatTest, FormatsLambdas) {
" LambdaBodyMustBeBreak);\n"
"};",
LLVMWithBeforeLambdaBody);
- LLVMWithBeforeLambdaBody.PackParameters.BinPack = FormatStyle::BPPS_OnePerLine;
+ LLVMWithBeforeLambdaBody.PackParameters.BinPack =
+ FormatStyle::BPPS_OnePerLine;
verifyFormat("FctAllOnSameLine_SLS_All([]() { return S; }, Fst, Second);",
LLVMWithBeforeLambdaBody);
verifyFormat(
More information about the cfe-commits
mailing list