Skip to content

[clang-format] Rename option AlwaysBreakTemplateDeclarations #81093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 61 additions & 56 deletions clang/docs/ClangFormatStyleOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1659,62 +1659,8 @@ the configuration (without a prefix: ``Auto``).

.. _AlwaysBreakTemplateDeclarations:

**AlwaysBreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakTemplateDeclarations>`
The template declaration breaking style to use.

Possible values:

* ``BTDS_Leave`` (in configuration: ``Leave``)
Do not change the line breaking before the declaration.

.. code-block:: c++

template <typename T>
T foo() {
}
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}

* ``BTDS_No`` (in configuration: ``No``)
Do not force break before declaration.
``PenaltyBreakTemplateDeclaration`` is taken into account.

.. code-block:: c++

template <typename T> T foo() {
}
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}

* ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
Force break after template declaration only when the following
declaration spans multiple lines.

.. code-block:: c++

template <typename T> T foo() {
}
template <typename T>
T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}

* ``BTDS_Yes`` (in configuration: ``Yes``)
Always break after template declaration.

.. code-block:: c++

template <typename T>
T foo() {
}
template <typename T>
T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}


**AlwaysBreakTemplateDeclarations** (``deprecated``) :versionbadge:`clang-format 3.4` :ref:`¶ <AlwaysBreakTemplateDeclarations>`
This option is renamed to ``BreakTemplateDeclarations``.

.. _AttributeMacros:

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

.. _BreakTemplateDeclarations:

**BreakTemplateDeclarations** (``BreakTemplateDeclarationsStyle``) :versionbadge:`clang-format 19` :ref:`¶ <BreakTemplateDeclarations>`
The template declaration breaking style to use.

Possible values:

* ``BTDS_Leave`` (in configuration: ``Leave``)
Do not change the line breaking before the declaration.

.. code-block:: c++

template <typename T>
T foo() {
}
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}

* ``BTDS_No`` (in configuration: ``No``)
Do not force break before declaration.
``PenaltyBreakTemplateDeclaration`` is taken into account.

.. code-block:: c++

template <typename T> T foo() {
}
template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}

* ``BTDS_MultiLine`` (in configuration: ``MultiLine``)
Force break after template declaration only when the following
declaration spans multiple lines.

.. code-block:: c++

template <typename T> T foo() {
}
template <typename T>
T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}

* ``BTDS_Yes`` (in configuration: ``Yes``)
Always break after template declaration.

.. code-block:: c++

template <typename T>
T foo() {
}
template <typename T>
T foo(int aaaaaaaaaaaaaaaaaaaaa,
int bbbbbbbbbbbbbbbbbbbbb) {
}



.. _ColumnLimit:

**ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ <ColumnLimit>`
Expand Down
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ AST Matchers
clang-format
------------

- ``AlwaysBreakTemplateDeclarations`` is deprecated and renamed to
``BreakTemplateDeclarations``.

libclang
--------

Expand Down
7 changes: 7 additions & 0 deletions clang/docs/tools/dump_format_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class State:
enum = None
nested_struct = None
version = None
deprecated = False

for line in self.header:
self.lineno += 1
Expand All @@ -327,6 +328,8 @@ class State:
match = re.match(r"/// \\version\s*(?P<version>[0-9.]+)*", line)
if match:
version = match.group("version")
elif line.startswith("/// @deprecated"):
deprecated = True
elif line.startswith("///"):
comment += self.__clean_comment_line(line)
elif line.startswith("enum"):
Expand All @@ -345,6 +348,9 @@ class State:
field_type, field_name = re.match(
r"([<>:\w(,\s)]+)\s+(\w+);", line
).groups()
if deprecated:
field_type = "deprecated"
deprecated = False

if not version:
self.__warning(f"missing version for {field_name}", line)
Expand Down Expand Up @@ -456,6 +462,7 @@ class State:
"std::vector<IncludeCategory>",
"std::vector<RawStringFormat>",
"std::optional<unsigned>",
"deprecated",
]:
if option.type in enums:
option.enum = enums[option.type]
Expand Down
7 changes: 6 additions & 1 deletion clang/include/clang/Format/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,9 @@ struct FormatStyle {
BTDS_Yes
};

/// The template declaration breaking style to use.
/// This option is renamed to ``BreakTemplateDeclarations``.
/// \version 3.4
/// @deprecated
BreakTemplateDeclarationsStyle AlwaysBreakTemplateDeclarations;

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

/// The template declaration breaking style to use.
/// \version 19
// BreakTemplateDeclarationsStyle BreakTemplateDeclarations;

/// If ``true``, consecutive namespace declarations will be on the same
/// line. If ``false``, each namespace is declared on a new line.
/// \code
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,8 @@ template <> struct MappingTraits<FormatStyle> {
if (!IO.outputting()) {
IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
IO.mapOptional("AllowAllConstructorInitializersOnNextLine", OnNextLine);
IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
IO.mapOptional("BreakBeforeInheritanceComma",
BreakBeforeInheritanceComma);
IO.mapOptional("BreakConstructorInitializersBeforeComma",
Expand Down Expand Up @@ -943,8 +945,6 @@ template <> struct MappingTraits<FormatStyle> {
Style.AlwaysBreakAfterReturnType);
IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
IO.mapOptional("BinPackArguments", Style.BinPackArguments);
IO.mapOptional("BinPackParameters", Style.BinPackParameters);
Expand All @@ -971,6 +971,8 @@ template <> struct MappingTraits<FormatStyle> {
Style.BreakConstructorInitializers);
IO.mapOptional("BreakInheritanceList", Style.BreakInheritanceList);
IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals);
IO.mapOptional("BreakTemplateDeclarations",
Style.AlwaysBreakTemplateDeclarations);
IO.mapOptional("ColumnLimit", Style.ColumnLimit);
IO.mapOptional("CommentPragmas", Style.CommentPragmas);
IO.mapOptional("CompactNamespaces", Style.CompactNamespaces);
Expand Down
13 changes: 13 additions & 0 deletions clang/unittests/Format/ConfigParseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,19 @@ TEST(ConfigParseTest, ParsesConfiguration) {
FormatStyle::RTBS_TopLevelDefinitions);

Style.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes;
CHECK_PARSE("BreakTemplateDeclarations: Leave",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Leave);
CHECK_PARSE("BreakTemplateDeclarations: No", AlwaysBreakTemplateDeclarations,
FormatStyle::BTDS_No);
CHECK_PARSE("BreakTemplateDeclarations: MultiLine",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
CHECK_PARSE("BreakTemplateDeclarations: Yes", AlwaysBreakTemplateDeclarations,
FormatStyle::BTDS_Yes);
CHECK_PARSE("BreakTemplateDeclarations: false",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_MultiLine);
CHECK_PARSE("BreakTemplateDeclarations: true",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Yes);
// For backward compatibility:
CHECK_PARSE("AlwaysBreakTemplateDeclarations: Leave",
AlwaysBreakTemplateDeclarations, FormatStyle::BTDS_Leave);
CHECK_PARSE("AlwaysBreakTemplateDeclarations: No",
Expand Down