Skip to content

Commit c5cbfc5

Browse files
authored
[clang-format] Rename option AlwaysBreakTemplateDeclarations (llvm#81093)
Drop the "Always" prefix to remove the self-contradiction.
1 parent 637c370 commit c5cbfc5

File tree

6 files changed

+94
-59
lines changed

6 files changed

+94
-59
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,62 +1659,8 @@ the configuration (without a prefix: ``Auto``).
16591659

16601660
.. _AlwaysBreakTemplateDeclarations:
16611661

1662-
**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 3.4` :ref:`<AlwaysBreakTemplateDeclarations>`
1663-
The template declaration breaking style to use.
1664-
1665-
Possible values:
1666-
1667-
* ``BTDS_Leave`` (in configuration: ``Leave``)
1668-
Do not change the line breaking before the declaration.
1669-
1670-
.. code-block:: c++
1671-
1672-
template <typename T>
1673-
T foo() {
1674-
}
1675-
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1676-
int bbbbbbbbbbbbbbbbbbbbb) {
1677-
}
1678-
1679-
* ``BTDS_No`` (in configuration: ``No``)
1680-
Do not force break before declaration.
1681-
``PenaltyBreakTemplateDeclaration`` is taken into account.
1682-
1683-
.. code-block:: c++
1684-
1685-
template <typename T> T foo() {
1686-
}
1687-
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
1688-
int bbbbbbbbbbbbbbbbbbbbb) {
1689-
}
1690-
1691-
* ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
1692-
Force break after template declaration only when the following
1693-
declaration spans multiple lines.
1694-
1695-
.. code-block:: c++
1696-
1697-
template <typename T> T foo() {
1698-
}
1699-
template <typename T>
1700-
T foo(int aaaaaaaaaaaaaaaaaaaaa,
1701-
int bbbbbbbbbbbbbbbbbbbbb) {
1702-
}
1703-
1704-
* ``BTDS_Yes`` (in configuration: ``Yes``)
1705-
Always break after template declaration.
1706-
1707-
.. code-block:: c++
1708-
1709-
template <typename T>
1710-
T foo() {
1711-
}
1712-
template <typename T>
1713-
T foo(int aaaaaaaaaaaaaaaaaaaaa,
1714-
int bbbbbbbbbbbbbbbbbbbbb) {
1715-
}
1716-
1717-
1662+
**AlwaysBreakTemplateDeclarations** (``deprecated``) :versionbadge:`clang-format 3.4` :ref:`<AlwaysBreakTemplateDeclarations>`
1663+
This option is renamed to ``BreakTemplateDeclarations``.
17181664

17191665
.. _AttributeMacros:
17201666

@@ -3014,6 +2960,65 @@ the configuration (without a prefix: ``Auto``).
30142960
string x =
30152961
"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
30162962

2963+
.. _BreakTemplateDeclarations:
2964+
2965+
**BreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 19` :ref:`<BreakTemplateDeclarations>`
2966+
The template declaration breaking style to use.
2967+
2968+
Possible values:
2969+
2970+
* ``BTDS_Leave`` (in configuration: ``Leave``)
2971+
Do not change the line breaking before the declaration.
2972+
2973+
.. code-block:: c++
2974+
2975+
template <typename T>
2976+
T foo() {
2977+
}
2978+
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
2979+
int bbbbbbbbbbbbbbbbbbbbb) {
2980+
}
2981+
2982+
* ``BTDS_No`` (in configuration: ``No``)
2983+
Do not force break before declaration.
2984+
``PenaltyBreakTemplateDeclaration`` is taken into account.
2985+
2986+
.. code-block:: c++
2987+
2988+
template <typename T> T foo() {
2989+
}
2990+
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
2991+
int bbbbbbbbbbbbbbbbbbbbb) {
2992+
}
2993+
2994+
* ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
2995+
Force break after template declaration only when the following
2996+
declaration spans multiple lines.
2997+
2998+
.. code-block:: c++
2999+
3000+
template <typename T> T foo() {
3001+
}
3002+
template <typename T>
3003+
T foo(int aaaaaaaaaaaaaaaaaaaaa,
3004+
int bbbbbbbbbbbbbbbbbbbbb) {
3005+
}
3006+
3007+
* ``BTDS_Yes`` (in configuration: ``Yes``)
3008+
Always break after template declaration.
3009+
3010+
.. code-block:: c++
3011+
3012+
template <typename T>
3013+
T foo() {
3014+
}
3015+
template <typename T>
3016+
T foo(int aaaaaaaaaaaaaaaaaaaaa,
3017+
int bbbbbbbbbbbbbbbbbbbbb) {
3018+
}
3019+
3020+
3021+
30173022
.. _ColumnLimit:
30183023

30193024
**ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`<ColumnLimit>`

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,9 @@ AST Matchers
291291
clang-format
292292
------------
293293

294+
- ``AlwaysBreakTemplateDeclarations`` is deprecated and renamed to
295+
``BreakTemplateDeclarations``.
296+
294297
libclang
295298
--------
296299

clang/docs/tools/dump_format_style.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ class State:
308308
enum = None
309309
nested_struct = None
310310
version = None
311+
deprecated = False
311312

312313
for line in self.header:
313314
self.lineno += 1
@@ -327,6 +328,8 @@ class State:
327328
match = re.match(r"/// \\version\s*(?P<version>[0-9.]+)*", line)
328329
if match:
329330
version = match.group("version")
331+
elif line.startswith("/// @deprecated"):
332+
deprecated = True
330333
elif line.startswith("///"):
331334
comment += self.__clean_comment_line(line)
332335
elif line.startswith("enum"):
@@ -345,6 +348,9 @@ class State:
345348
field_type, field_name = re.match(
346349
r"([<>:\w(,\s)]+)\s+(\w+);", line
347350
).groups()
351+
if deprecated:
352+
field_type = "deprecated"
353+
deprecated = False
348354

349355
if not version:
350356
self.__warning(f"missing version for {field_name}", line)
@@ -456,6 +462,7 @@ class State:
456462
"std::vector<IncludeCategory>",
457463
"std::vector<RawStringFormat>",
458464
"std::optional<unsigned>",
465+
"deprecated",
459466
]:
460467
if option.type in enums:
461468
option.enum = enums[option.type]

clang/include/clang/Format/Format.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,9 @@ struct FormatStyle {
10751075
BTDS_Yes
10761076
};
10771077

1078-
/// The template declaration breaking style to use.
1078+
/// This option is renamed to ``BreakTemplateDeclarations``.
10791079
/// \version 3.4
1080+
/// @deprecated
10801081
BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;
10811082

10821083
/// A vector of strings that should be interpreted as attributes/qualifiers
@@ -2293,6 +2294,10 @@ struct FormatStyle {
22932294
/// \version 7
22942295
BreakInheritanceListStyle BreakInheritanceList;
22952296

2297+
/// The template declaration breaking style to use.
2298+
/// \version 19
2299+
// BreakTemplateDeclarationsStyle BreakTemplateDeclarations;
2300+
22962301
/// If ``true``, consecutive namespace declarations will be on the same
22972302
/// line. If ``false``, each namespace is declared on a new line.
22982303
/// \code

clang/lib/Format/Format.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ template <> struct MappingTraits<FormatStyle> {
877877
if (!IO.outputting()) {
878878
IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
879879
IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
880+
IO.mapOptional("AlwaysBreakTemplateDeclarations",
881+
Style.AlwaysBreakTemplateDeclarations);
880882
IO.mapOptional("BreakBeforeInheritanceComma",
881883
BreakBeforeInheritanceComma);
882884
IO.mapOptional("BreakConstructorInitializersBeforeComma",
@@ -943,8 +945,6 @@ template <> struct MappingTraits<FormatStyle> {
943945
Style.AlwaysBreakAfterReturnType);
944946
IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
945947
Style.AlwaysBreakBeforeMultilineStrings);
946-
IO.mapOptional("AlwaysBreakTemplateDeclarations",
947-
Style.AlwaysBreakTemplateDeclarations);
948948
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
949949
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
950950
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
@@ -971,6 +971,8 @@ template <> struct MappingTraits<FormatStyle> {
971971
Style.BreakConstructorInitializers);
972972
IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList);
973973
IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals);
974+
IO.mapOptional("BreakTemplateDeclarations",
975+
Style.AlwaysBreakTemplateDeclarations);
974976
IO.mapOptional("ColumnLimit", Style.ColumnLimit);
975977
IO.mapOptional("CommentPragmas", Style.CommentPragmas);
976978
IO.mapOptional("CompactNamespaces", Style.CompactNamespaces);

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,19 @@ TEST(ConfigParseTest, ParsesConfiguration) {
695695
FormatStyle::RTBS_TopLevelDefinitions);
696696

697697
Style.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
698+
CHECK_PARSE("BreakTemplateDeclarations: Leave",
699+
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Leave);
700+
CHECK_PARSE("BreakTemplateDeclarations: No", AlwaysBreakTemplateDeclarations,
701+
FormatStyle::BTDS_No);
702+
CHECK_PARSE("BreakTemplateDeclarations: MultiLine",
703+
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
704+
CHECK_PARSE("BreakTemplateDeclarations: Yes", AlwaysBreakTemplateDeclarations,
705+
FormatStyle::BTDS_Yes);
706+
CHECK_PARSE("BreakTemplateDeclarations: false",
707+
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
708+
CHECK_PARSE("BreakTemplateDeclarations: true",
709+
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Yes);
710+
// For backward compatibility:
698711
CHECK_PARSE("AlwaysBreakTemplateDeclarations: Leave",
699712
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Leave);
700713
CHECK_PARSE("AlwaysBreakTemplateDeclarations: No",

0 commit comments

Comments
 (0)