[clang] [clang-format] Add BreakParametersAfter formatting option (PR #181281)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 7 18:00:20 PST 2026
https://github.com/Ezlanding1 updated https://github.com/llvm/llvm-project/pull/181281
>From a2a04832e3f93b879f3bee4b235c4e3ab5b94400 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 1/9] 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 5ba117c231ad5..592f94c99010b 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5252,6 +5252,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 43bea4b80cb8a..0073ad96239cb 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1254,6 +1254,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 ``:``
@@ -5694,6 +5723,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 1e68de531791f..6a68012525144 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1355,6 +1355,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 3d7741fde79127c386139ced866f6d932d04583b 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 2/9] 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 b1c1afbf8684d..516c997e75cfc 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4246,6 +4246,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 caffe220d477bd8813c09bb67912544b7a24ce08 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 3/9] 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 516c997e75cfc..a1d7ba49d3aad 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4258,10 +4258,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 99c3f842e78e007c39d31ce9ba42c352c34519c8 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 4/9] 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 a1d7ba49d3aad..236c6e7ea89f7 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4247,7 +4247,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 ad23bb5edf114bb12b69151218c5a6f214c30bdf 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 5/9] 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 592f94c99010b..a0673cb8dcbc2 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3752,6 +3752,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>`
@@ -5252,37 +5283,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 0073ad96239cb..25ad43d588485 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1254,35 +1254,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 ``:``
@@ -2638,6 +2609,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;
@@ -5723,7 +5723,6 @@ struct FormatStyle {
BinPackArguments == R.BinPackArguments &&
BinPackLongBracedList == R.BinPackLongBracedList &&
BinPackParameters == R.BinPackParameters &&
- MaxParametersOnLine == R.MaxParametersOnLine &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
BracedInitializerIndentWidth == R.BracedInitializerIndentWidth &&
BreakAdjacentStringLiterals == R.BreakAdjacentStringLiterals &&
@@ -5755,6 +5754,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 6a68012525144..1409028e73731 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1355,7 +1355,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 236c6e7ea89f7..e9b07a1578e49 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4246,11 +4246,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()) {
@@ -4258,8 +4257,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 da2af2419140b4d76a8ca7f993b1968bf933ad40 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 6/9] 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 1409028e73731..e0388a17f2ef0 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1729,6 +1729,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 0a116b770f52a..ef442a17a7a8f 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -283,6 +283,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 33836e28289b4..18b33e3869dc7 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8164,6 +8164,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 5e69bd95070fca6e9d18c77b03903e0052d466c1 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 7/9] 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 e9b07a1578e49..44be5ead41e39 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4246,11 +4246,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 18b33e3869dc7..b9a07d960e67c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8196,7 +8196,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"
@@ -8241,7 +8245,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 b87dc5668c7508eac0f7036fcec7185b880f638c 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 8/9] 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 a0673cb8dcbc2..a802c745b48b0 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2153,27 +2153,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>`
@@ -2192,44 +2171,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>`
@@ -3752,37 +3693,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>`
@@ -5627,6 +5537,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>`
@@ -5700,6 +5675,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 25ad43d588485..0ab16e94b2ed2 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1188,25 +1188,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.
@@ -1223,37 +1204,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 ``:``
@@ -2609,35 +2559,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;
@@ -4001,6 +3922,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.
@@ -4063,6 +4050,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;
@@ -5720,9 +5778,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 &&
@@ -5754,7 +5810,6 @@ struct FormatStyle {
BreakFunctionDefinitionParameters ==
R.BreakFunctionDefinitionParameters &&
BreakInheritanceList == R.BreakInheritanceList &&
- BreakParametersAfter == R.BreakParametersAfter &&
BreakStringLiterals == R.BreakStringLiterals &&
BreakTemplateDeclarations == R.BreakTemplateDeclarations &&
ColumnLimit == R.ColumnLimit && CommentPragmas == R.CommentPragmas &&
@@ -5816,7 +5871,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 1272bb72d423f..fcbe29853e282 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -480,7 +480,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 &&
@@ -2054,11 +2055,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);
@@ -2091,12 +2093,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 =
@@ -2107,7 +2111,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 e0388a17f2ef0..1c20615192cce 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -142,12 +142,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);
@@ -532,6 +545,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
@@ -544,6 +564,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);
@@ -1130,9 +1157,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);
@@ -1251,8 +1278,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);
@@ -1355,7 +1384,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
@@ -1681,9 +1709,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,
@@ -1729,7 +1755,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;
@@ -1794,7 +1819,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;
@@ -2086,7 +2115,7 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) {
ChromiumStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
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;
@@ -2100,8 +2129,8 @@ FormatStyle getMozillaStyle() {
MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
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;
@@ -2358,7 +2387,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 44be5ead41e39..4dacffb229935 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4246,8 +4246,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) {
@@ -5729,7 +5735,7 @@ bool TokenAnnotator::mustBreakBefore(const 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 b9a07d960e67c..2459a21d9af54 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8171,88 +8171,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 0fea3705e5493c8c1ff37ba9b0a66ea0d8aeebd9 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 9/9] Update unit tests
---
clang/unittests/Format/AlignBracketsTest.cpp | 26 ++---
clang/unittests/Format/ConfigParseTest.cpp | 51 +++++++---
clang/unittests/Format/FormatTest.cpp | 94 ++++++++++---------
clang/unittests/Format/FormatTestComments.cpp | 8 +-
clang/unittests/Format/FormatTestObjC.cpp | 4 +-
5 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/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index ef442a17a7a8f..7ad3f1c2b834b 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);
@@ -283,7 +282,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);
@@ -486,19 +484,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);
@@ -527,6 +529,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 2459a21d9af54..41f8fb97fc199 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -2359,7 +2359,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"
@@ -5125,7 +5125,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;
@@ -7319,7 +7319,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"
@@ -7473,7 +7473,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"
@@ -7654,7 +7654,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"
@@ -7848,7 +7848,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"
@@ -7882,7 +7882,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.
@@ -8081,7 +8081,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;
@@ -8118,7 +8118,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"
@@ -8152,7 +8152,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"
@@ -8165,9 +8165,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"
@@ -8183,15 +8183,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);
}
@@ -8376,7 +8384,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"
@@ -8550,7 +8558,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)
@@ -8983,8 +8991,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"
@@ -9015,8 +9023,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);",
@@ -9567,7 +9575,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"
@@ -10784,7 +10792,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"
@@ -13976,7 +13984,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"
@@ -14251,9 +14259,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"
@@ -14689,7 +14697,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; }};",
@@ -19690,7 +19698,7 @@ TEST_F(FormatTest, AlignConsecutiveAssignments) {
// 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"
@@ -20124,7 +20132,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
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"
@@ -20332,7 +20340,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
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"
@@ -20346,7 +20354,7 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
" uint32_t *c,\n"
" bool d) {}",
Alignment);
- Alignment.BinPackParameters = FormatStyle::BPPS_BinPack;
+ Alignment.PackParameters.BinPack = FormatStyle::BPPS_BinPack;
Alignment.ColumnLimit = 80;
// Bug 33507
@@ -20878,7 +20886,7 @@ TEST_F(FormatTest, AlignWithLineBreaks) {
Style);
// clang-format on
- Style.BinPackArguments = false;
+ Style.PackArguments.BinPack = FormatStyle::BPAS_OnePerLine;
// clang-format off
verifyFormat("void SomeFunc() {\n"
@@ -23654,7 +23662,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"
@@ -23972,7 +23980,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(
@@ -24267,7 +24275,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"
@@ -24285,7 +24293,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"
@@ -29075,11 +29083,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.
More information about the cfe-commits
mailing list