Skip to content

Commit

Permalink
[clang-format] Rename option AlwaysBreakAfterReturnType. (#80827)
Browse files Browse the repository at this point in the history
Changes the option to BreakAfterReturnType option, with a more relevant
name, deprecating and replacing AlwaysBreakAfterReturnType.
Following up on #78010.
  • Loading branch information
rmarker committed Feb 13, 2024
1 parent 070fad4 commit 91dcf53
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 111 deletions.
221 changes: 113 additions & 108 deletions clang/docs/ClangFormatStyleOptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1531,114 +1531,8 @@ the configuration (without a prefix: ``Auto``).

.. _AlwaysBreakAfterReturnType:

**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.8` :ref:`<AlwaysBreakAfterReturnType>`
The function declaration return type breaking style to use.

Possible values:

* ``RTBS_None`` (in configuration: ``None``)
This is **deprecated**. See ``Automatic`` below.

* ``RTBS_Automatic`` (in configuration: ``Automatic``)
Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.

.. code-block:: c++

class A {
int f() { return 0; };
};
int f();
int f() { return 1; }
int
LongName::AnotherLongName();

* ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``)
Same as ``Automatic`` above, except that there is no break after short
return types.

.. code-block:: c++

class A {
int f() { return 0; };
};
int f();
int f() { return 1; }
int LongName::
AnotherLongName();

* ``RTBS_All`` (in configuration: ``All``)
Always break after the return type.

.. code-block:: c++

class A {
int
f() {
return 0;
};
};
int
f();
int
f() {
return 1;
}
int
LongName::AnotherLongName();

* ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
Always break after the return types of top-level functions.

.. code-block:: c++

class A {
int f() { return 0; };
};
int
f();
int
f() {
return 1;
}
int
LongName::AnotherLongName();

* ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
Always break after the return type of function definitions.

.. code-block:: c++

class A {
int
f() {
return 0;
};
};
int f();
int
f() {
return 1;
}
int
LongName::AnotherLongName();

* ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
Always break after the return type of top-level definitions.

.. code-block:: c++

class A {
int f() { return 0; };
};
int f();
int
f() {
return 1;
}
int
LongName::AnotherLongName();


**AlwaysBreakAfterReturnType** (``deprecated``) :versionbadge:`clang-format 3.8` :ref:`<AlwaysBreakAfterReturnType>`
This option is renamed to ``BreakAfterReturnType``.

.. _AlwaysBreakBeforeMultilineStrings:

Expand Down Expand Up @@ -2219,6 +2113,117 @@ the configuration (without a prefix: ``Auto``).
@Mock
DataLoad loader;
.. _BreakAfterReturnType:

**BreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 19` :ref:`<BreakAfterReturnType>`
The function declaration return type breaking style to use.

Possible values:

* ``RTBS_None`` (in configuration: ``None``)
This is **deprecated**. See ``Automatic`` below.

* ``RTBS_Automatic`` (in configuration: ``Automatic``)
Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.

.. code-block:: c++

class A {
int f() { return 0; };
};
int f();
int f() { return 1; }
int
LongName::AnotherLongName();

* ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``)
Same as ``Automatic`` above, except that there is no break after short
return types.

.. code-block:: c++

class A {
int f() { return 0; };
};
int f();
int f() { return 1; }
int LongName::
AnotherLongName();

* ``RTBS_All`` (in configuration: ``All``)
Always break after the return type.

.. code-block:: c++

class A {
int
f() {
return 0;
};
};
int
f();
int
f() {
return 1;
}
int
LongName::AnotherLongName();

* ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
Always break after the return types of top-level functions.

.. code-block:: c++

class A {
int f() { return 0; };
};
int
f();
int
f() {
return 1;
}
int
LongName::AnotherLongName();

* ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
Always break after the return type of function definitions.

.. code-block:: c++

class A {
int
f() {
return 0;
};
};
int f();
int
f() {
return 1;
}
int
LongName::AnotherLongName();

* ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
Always break after the return type of top-level definitions.

.. code-block:: c++

class A {
int f() { return 0; };
};
int f();
int
f() {
return 1;
}
int
LongName::AnotherLongName();



.. _BreakArrays:

**BreakArrays** (``Boolean``) :versionbadge:`clang-format 16` :ref:`<BreakArrays>`
Expand Down
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ clang-format

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

libclang
--------
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 @@ -1010,8 +1010,9 @@ struct FormatStyle {
/// \version 3.7
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;

/// The function declaration return type breaking style to use.
/// This option is renamed to ``BreakAfterReturnType``.
/// \version 3.8
/// @deprecated
ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;

/// If ``true``, always break before multiline string literals.
Expand Down Expand Up @@ -1576,6 +1577,10 @@ struct FormatStyle {
/// \version 16
AttributeBreakingStyle BreakAfterAttributes;

/// The function declaration return type breaking style to use.
/// \version 19
// ReturnTypeBreakingStyle BreakAfterReturnType;

/// If ``true``, clang-format will always break after a Json array ``[``
/// otherwise it will scan until the closing ``]`` to determine if it should
/// add newlines between elements (prettier compatible).
Expand Down
5 changes: 3 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("AlwaysBreakAfterReturnType",
Style.AlwaysBreakAfterReturnType);
IO.mapOptional("AlwaysBreakTemplateDeclarations",
Style.BreakTemplateDeclarations);
IO.mapOptional("BreakBeforeInheritanceComma",
Expand Down Expand Up @@ -941,8 +943,6 @@ template <> struct MappingTraits<FormatStyle> {
Style.AllowShortLoopsOnASingleLine);
IO.mapOptional("AlwaysBreakAfterDefinitionReturnType",
Style.AlwaysBreakAfterDefinitionReturnType);
IO.mapOptional("AlwaysBreakAfterReturnType",
Style.AlwaysBreakAfterReturnType);
IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
Expand All @@ -957,6 +957,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("BreakAfterAttributes", Style.BreakAfterAttributes);
IO.mapOptional("BreakAfterJavaFieldAnnotations",
Style.BreakAfterJavaFieldAnnotations);
IO.mapOptional("BreakAfterReturnType", Style.AlwaysBreakAfterReturnType);
IO.mapOptional("BreakArrays", Style.BreakArrays);
IO.mapOptional("BreakBeforeBinaryOperators",
Style.BreakBeforeBinaryOperators);
Expand Down
16 changes: 16 additions & 0 deletions clang/unittests/Format/ConfigParseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,22 @@ TEST(ConfigParseTest, ParsesConfiguration) {
BraceWrapping.AfterControlStatement, FormatStyle::BWACS_Never);

Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
CHECK_PARSE("BreakAfterReturnType: None", AlwaysBreakAfterReturnType,
FormatStyle::RTBS_None);
CHECK_PARSE("BreakAfterReturnType: Automatic", AlwaysBreakAfterReturnType,
FormatStyle::RTBS_Automatic);
CHECK_PARSE("BreakAfterReturnType: ExceptShortType",
AlwaysBreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
CHECK_PARSE("BreakAfterReturnType: All", AlwaysBreakAfterReturnType,
FormatStyle::RTBS_All);
CHECK_PARSE("BreakAfterReturnType: TopLevel", AlwaysBreakAfterReturnType,
FormatStyle::RTBS_TopLevel);
CHECK_PARSE("BreakAfterReturnType: AllDefinitions",
AlwaysBreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
CHECK_PARSE("BreakAfterReturnType: TopLevelDefinitions",
AlwaysBreakAfterReturnType,
FormatStyle::RTBS_TopLevelDefinitions);
// For backward compatibility:
CHECK_PARSE("AlwaysBreakAfterReturnType: None", AlwaysBreakAfterReturnType,
FormatStyle::RTBS_None);
CHECK_PARSE("AlwaysBreakAfterReturnType: Automatic",
Expand Down

0 comments on commit 91dcf53

Please sign in to comment.