Skip to content

Commit a768adb

Browse files
committed
switch back to bool
1 parent a437f23 commit a768adb

File tree

7 files changed

+54
-89
lines changed

7 files changed

+54
-89
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,43 +3423,32 @@ the configuration (without a prefix: ``Auto``).
34233423

34243424
.. _BreakBeforeTemplateCloser:
34253425

3426-
**BreakBeforeTemplateCloser** (``BreakBeforeTemplateCloserStyle``) :versionbadge:`clang-format 21` :ref:`<BreakBeforeTemplateCloser>`
3427-
The style of when a line break will be placed before the ``>`` that closes
3428-
a template.
3426+
**BreakBeforeTemplateCloser** (``Boolean``) :versionbadge:`clang-format 21` :ref:`<BreakBeforeTemplateCloser>`
3427+
If ``true``, a line break will be placed before the ``>`` in a block
3428+
indented template declaration.
34293429

3430-
Possible values:
3431-
3432-
* ``BBTCS_Never`` (in configuration: ``Never``)
3433-
Never break before a template closer.
3434-
3435-
.. code-block:: c++
3436-
3437-
template <typename Foo, typename Bar>
3438-
3439-
template <typename Foo,
3440-
typename Bar>
3441-
3442-
template <
3443-
typename Foo,
3444-
typename Bar>
3445-
3446-
* ``BBTCS_BlockIndent`` (in configuration: ``BlockIndent``)
3447-
Break before a template closer if the template has broken into block
3448-
indent style.
3430+
.. code-block:: c++
34493431

3450-
.. code-block:: c++
3432+
true:
3433+
template <typename Foo, typename Bar>
34513434

3452-
template <typename Foo, typename Bar>
3435+
template <typename Foo,
3436+
typename Bar>
34533437

3454-
template <typename Foo,
3455-
typename Bar>
3438+
template <
3439+
typename Foo,
3440+
typename Bar
3441+
>
34563442

3457-
template <
3458-
typename Foo,
3459-
typename Bar
3460-
>
3443+
false:
3444+
template <typename Foo, typename Bar>
34613445

3446+
template <typename Foo,
3447+
typename Bar>
34623448

3449+
template <
3450+
typename Foo,
3451+
typename Bar>
34633452

34643453
.. _BreakBeforeTernaryOperators:
34653454

clang/include/clang/Format/Format.h

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,40 +2252,32 @@ struct FormatStyle {
22522252
/// \version 16
22532253
BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
22542254

2255-
/// Different styles for whether to break before a template closer.
2256-
enum BreakBeforeTemplateCloserStyle : int8_t {
2257-
/// Never break before a template closer.
2258-
/// \code
2259-
/// template <typename Foo, typename Bar>
2260-
///
2261-
/// template <typename Foo,
2262-
/// typename Bar>
2263-
///
2264-
/// template <
2265-
/// typename Foo,
2266-
/// typename Bar>
2267-
/// \endcode
2268-
BBTCS_Never,
2269-
/// Break before a template closer if the template has broken into block
2270-
/// indent style.
2271-
/// \code
2272-
/// template <typename Foo, typename Bar>
2273-
///
2274-
/// template <typename Foo,
2275-
/// typename Bar>
2276-
///
2277-
/// template <
2278-
/// typename Foo,
2279-
/// typename Bar
2280-
/// >
2281-
/// \endcode
2282-
BBTCS_BlockIndent,
2283-
};
2284-
2285-
/// The style of when a line break will be placed before the ``>`` that closes
2286-
/// a template.
2255+
/// If ``true``, a line break will be placed before the ``>`` in a block
2256+
/// indented template declaration.
2257+
/// \code
2258+
/// true:
2259+
/// template <typename Foo, typename Bar>
2260+
///
2261+
/// template <typename Foo,
2262+
/// typename Bar>
2263+
///
2264+
/// template <
2265+
/// typename Foo,
2266+
/// typename Bar
2267+
/// >
2268+
///
2269+
/// false:
2270+
/// template <typename Foo, typename Bar>
2271+
///
2272+
/// template <typename Foo,
2273+
/// typename Bar>
2274+
///
2275+
/// template <
2276+
/// typename Foo,
2277+
/// typename Bar>
2278+
/// \endcode
22872279
/// \version 21
2288-
BreakBeforeTemplateCloserStyle BreakBeforeTemplateCloser;
2280+
bool BreakBeforeTemplateCloser;
22892281

22902282
/// If ``true``, ternary operators will be placed after line breaks.
22912283
/// \code

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
304304
Current.closesBlockOrBlockTypeList(Style))) {
305305
return false;
306306
}
307-
if (Style.BreakBeforeTemplateCloser == FormatStyle::BBTCS_BlockIndent &&
308-
Current.is(TT_TemplateCloser) && !CurrentState.BreakBeforeClosingAngle) {
307+
if (Style.BreakBeforeTemplateCloser && Current.is(TT_TemplateCloser) &&
308+
!CurrentState.BreakBeforeClosingAngle) {
309309
return false;
310310
}
311311
// The opening "{" of a braced list has to be on the same line as the first
@@ -1249,10 +1249,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
12491249
Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
12501250
}
12511251

1252-
if (PreviousNonComment && PreviousNonComment->is(TT_TemplateOpener)) {
1253-
CurrentState.BreakBeforeClosingAngle =
1254-
Style.BreakBeforeTemplateCloser == FormatStyle::BBTCS_BlockIndent;
1255-
}
1252+
if (PreviousNonComment && PreviousNonComment->is(TT_TemplateOpener))
1253+
CurrentState.BreakBeforeClosingAngle = Style.BreakBeforeTemplateCloser;
12561254

12571255
if (CurrentState.AvoidBinPacking) {
12581256
// If we are breaking after '(', '{', '<', or this is the break after a ':'
@@ -1390,8 +1388,8 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
13901388
State.Stack.size() > 1) {
13911389
return State.Stack[State.Stack.size() - 2].LastSpace;
13921390
}
1393-
if (Style.BreakBeforeTemplateCloser == FormatStyle::BBTCS_BlockIndent &&
1394-
Current.is(TT_TemplateCloser) && State.Stack.size() > 1) {
1391+
if (Style.BreakBeforeTemplateCloser && Current.is(TT_TemplateCloser) &&
1392+
State.Stack.size() > 1) {
13951393
return State.Stack[State.Stack.size() - 2].LastSpace;
13961394
}
13971395
if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())

clang/lib/Format/Format.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,6 @@ struct ScalarEnumerationTraits<FormatStyle::BreakBeforeInlineASMColonStyle> {
256256
}
257257
};
258258

259-
template <>
260-
struct ScalarEnumerationTraits<FormatStyle::BreakBeforeTemplateCloserStyle> {
261-
static void enumeration(IO &IO,
262-
FormatStyle::BreakBeforeTemplateCloserStyle &Value) {
263-
IO.enumCase(Value, "Never", FormatStyle::BBTCS_Never);
264-
IO.enumCase(Value, "BlockIndent", FormatStyle::BBTCS_BlockIndent);
265-
}
266-
};
267-
268259
template <>
269260
struct ScalarEnumerationTraits<FormatStyle::BreakBinaryOperationsStyle> {
270261
static void enumeration(IO &IO,
@@ -1546,7 +1537,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
15461537
LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
15471538
LLVMStyle.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Always;
15481539
LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
1549-
LLVMStyle.BreakBeforeTemplateCloser = FormatStyle::BBTCS_Never;
1540+
LLVMStyle.BreakBeforeTemplateCloser = false;
15501541
LLVMStyle.BreakBeforeTernaryOperators = true;
15511542
LLVMStyle.BreakBinaryOperations = FormatStyle::BBO_Never;
15521543
LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6329,7 +6329,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
63296329
return false;
63306330

63316331
if (Right.is(TT_TemplateCloser))
6332-
return Style.BreakBeforeTemplateCloser != FormatStyle::BBTCS_Never;
6332+
return Style.BreakBeforeTemplateCloser;
63336333
if (Right.is(tok::r_square) && Right.MatchingParen &&
63346334
Right.MatchingParen->is(TT_LambdaLSquare)) {
63356335
return false;

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
170170
CHECK_PARSE_BOOL(BinPackArguments);
171171
CHECK_PARSE_BOOL(BreakAdjacentStringLiterals);
172172
CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
173+
CHECK_PARSE_BOOL(BreakBeforeTemplateCloser);
173174
CHECK_PARSE_BOOL(BreakBeforeTernaryOperators);
174175
CHECK_PARSE_BOOL(BreakStringLiterals);
175176
CHECK_PARSE_BOOL(CompactNamespaces);
@@ -435,12 +436,6 @@ TEST(ConfigParseTest, ParsesConfiguration) {
435436
CHECK_PARSE("BreakBeforeBinaryOperators: true", BreakBeforeBinaryOperators,
436437
FormatStyle::BOS_All);
437438

438-
Style.BreakBeforeTemplateCloser = FormatStyle::BBTCS_Never;
439-
CHECK_PARSE("BreakBeforeTemplateCloser: BlockIndent",
440-
BreakBeforeTemplateCloser, FormatStyle::BBTCS_BlockIndent);
441-
CHECK_PARSE("BreakBeforeTemplateCloser: Never", BreakBeforeTemplateCloser,
442-
FormatStyle::BBTCS_Never);
443-
444439
Style.BreakBinaryOperations = FormatStyle::BBO_Never;
445440
CHECK_PARSE("BreakBinaryOperations: OnePerLine", BreakBinaryOperations,
446441
FormatStyle::BBO_OnePerLine);

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11242,7 +11242,7 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1124211242
"void foo() {}",
1124311243
Style);
1124411244

11245-
Style.BreakBeforeTemplateCloser = FormatStyle::BBTCS_BlockIndent;
11245+
Style.BreakBeforeTemplateCloser = true;
1124611246
// BreakBeforeTemplateCloser should NOT force template declarations onto
1124711247
// multiple lines.
1124811248
verifyFormat("template <typename Foo>\n"

0 commit comments

Comments
 (0)