Skip to content

Commit 91dcf53

Browse files
authored
[clang-format] Rename option AlwaysBreakAfterReturnType. (#80827)
Changes the option to BreakAfterReturnType option, with a more relevant name, deprecating and replacing AlwaysBreakAfterReturnType. Following up on #78010.
1 parent 070fad4 commit 91dcf53

File tree

5 files changed

+140
-111
lines changed

5 files changed

+140
-111
lines changed

clang/docs/ClangFormatStyleOptions.rst

Lines changed: 113 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,114 +1531,8 @@ the configuration (without a prefix: ``Auto``).
15311531

15321532
.. _AlwaysBreakAfterReturnType:
15331533

1534-
**AlwaysBreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 3.8` :ref:`<AlwaysBreakAfterReturnType>`
1535-
The function declaration return type breaking style to use.
1536-
1537-
Possible values:
1538-
1539-
* ``RTBS_None`` (in configuration: ``None``)
1540-
This is **deprecated**. See ``Automatic`` below.
1541-
1542-
* ``RTBS_Automatic`` (in configuration: ``Automatic``)
1543-
Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
1544-
1545-
.. code-block:: c++
1546-
1547-
class A {
1548-
int f() { return 0; };
1549-
};
1550-
int f();
1551-
int f() { return 1; }
1552-
int
1553-
LongName::AnotherLongName();
1554-
1555-
* ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``)
1556-
Same as ``Automatic`` above, except that there is no break after short
1557-
return types.
1558-
1559-
.. code-block:: c++
1560-
1561-
class A {
1562-
int f() { return 0; };
1563-
};
1564-
int f();
1565-
int f() { return 1; }
1566-
int LongName::
1567-
AnotherLongName();
1568-
1569-
* ``RTBS_All`` (in configuration: ``All``)
1570-
Always break after the return type.
1571-
1572-
.. code-block:: c++
1573-
1574-
class A {
1575-
int
1576-
f() {
1577-
return 0;
1578-
};
1579-
};
1580-
int
1581-
f();
1582-
int
1583-
f() {
1584-
return 1;
1585-
}
1586-
int
1587-
LongName::AnotherLongName();
1588-
1589-
* ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
1590-
Always break after the return types of top-level functions.
1591-
1592-
.. code-block:: c++
1593-
1594-
class A {
1595-
int f() { return 0; };
1596-
};
1597-
int
1598-
f();
1599-
int
1600-
f() {
1601-
return 1;
1602-
}
1603-
int
1604-
LongName::AnotherLongName();
1605-
1606-
* ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
1607-
Always break after the return type of function definitions.
1608-
1609-
.. code-block:: c++
1610-
1611-
class A {
1612-
int
1613-
f() {
1614-
return 0;
1615-
};
1616-
};
1617-
int f();
1618-
int
1619-
f() {
1620-
return 1;
1621-
}
1622-
int
1623-
LongName::AnotherLongName();
1624-
1625-
* ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
1626-
Always break after the return type of top-level definitions.
1627-
1628-
.. code-block:: c++
1629-
1630-
class A {
1631-
int f() { return 0; };
1632-
};
1633-
int f();
1634-
int
1635-
f() {
1636-
return 1;
1637-
}
1638-
int
1639-
LongName::AnotherLongName();
1640-
1641-
1534+
**AlwaysBreakAfterReturnType** (``deprecated``) :versionbadge:`clang-format 3.8` :ref:`<AlwaysBreakAfterReturnType>`
1535+
This option is renamed to ``BreakAfterReturnType``.
16421536

16431537
.. _AlwaysBreakBeforeMultilineStrings:
16441538

@@ -2219,6 +2113,117 @@ the configuration (without a prefix: ``Auto``).
22192113
@Mock
22202114
DataLoad loader;
22212115
2116+
.. _BreakAfterReturnType:
2117+
2118+
**BreakAfterReturnType** (``ReturnTypeBreakingStyle``) :versionbadge:`clang-format 19` :ref:`<BreakAfterReturnType>`
2119+
The function declaration return type breaking style to use.
2120+
2121+
Possible values:
2122+
2123+
* ``RTBS_None`` (in configuration: ``None``)
2124+
This is **deprecated**. See ``Automatic`` below.
2125+
2126+
* ``RTBS_Automatic`` (in configuration: ``Automatic``)
2127+
Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
2128+
2129+
.. code-block:: c++
2130+
2131+
class A {
2132+
int f() { return 0; };
2133+
};
2134+
int f();
2135+
int f() { return 1; }
2136+
int
2137+
LongName::AnotherLongName();
2138+
2139+
* ``RTBS_ExceptShortType`` (in configuration: ``ExceptShortType``)
2140+
Same as ``Automatic`` above, except that there is no break after short
2141+
return types.
2142+
2143+
.. code-block:: c++
2144+
2145+
class A {
2146+
int f() { return 0; };
2147+
};
2148+
int f();
2149+
int f() { return 1; }
2150+
int LongName::
2151+
AnotherLongName();
2152+
2153+
* ``RTBS_All`` (in configuration: ``All``)
2154+
Always break after the return type.
2155+
2156+
.. code-block:: c++
2157+
2158+
class A {
2159+
int
2160+
f() {
2161+
return 0;
2162+
};
2163+
};
2164+
int
2165+
f();
2166+
int
2167+
f() {
2168+
return 1;
2169+
}
2170+
int
2171+
LongName::AnotherLongName();
2172+
2173+
* ``RTBS_TopLevel`` (in configuration: ``TopLevel``)
2174+
Always break after the return types of top-level functions.
2175+
2176+
.. code-block:: c++
2177+
2178+
class A {
2179+
int f() { return 0; };
2180+
};
2181+
int
2182+
f();
2183+
int
2184+
f() {
2185+
return 1;
2186+
}
2187+
int
2188+
LongName::AnotherLongName();
2189+
2190+
* ``RTBS_AllDefinitions`` (in configuration: ``AllDefinitions``)
2191+
Always break after the return type of function definitions.
2192+
2193+
.. code-block:: c++
2194+
2195+
class A {
2196+
int
2197+
f() {
2198+
return 0;
2199+
};
2200+
};
2201+
int f();
2202+
int
2203+
f() {
2204+
return 1;
2205+
}
2206+
int
2207+
LongName::AnotherLongName();
2208+
2209+
* ``RTBS_TopLevelDefinitions`` (in configuration: ``TopLevelDefinitions``)
2210+
Always break after the return type of top-level definitions.
2211+
2212+
.. code-block:: c++
2213+
2214+
class A {
2215+
int f() { return 0; };
2216+
};
2217+
int f();
2218+
int
2219+
f() {
2220+
return 1;
2221+
}
2222+
int
2223+
LongName::AnotherLongName();
2224+
2225+
2226+
22222227
.. _BreakArrays:
22232228

22242229
**BreakArrays** (``Boolean``) :versionbadge:`clang-format 16` :ref:`<BreakArrays>`

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ clang-format
296296

297297
- ``AlwaysBreakTemplateDeclarations`` is deprecated and renamed to
298298
``BreakTemplateDeclarations``.
299+
- ``AlwaysBreakAfterReturnType`` is deprecated and renamed to
300+
``BreakAfterReturnType``.
299301

300302
libclang
301303
--------

clang/include/clang/Format/Format.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,8 +1010,9 @@ struct FormatStyle {
10101010
/// \version 3.7
10111011
DefinitionReturnTypeBreakingStyle AlwaysBreakAfterDefinitionReturnType;
10121012

1013-
/// The function declaration return type breaking style to use.
1013+
/// This option is renamed to ``BreakAfterReturnType``.
10141014
/// \version 3.8
1015+
/// @deprecated
10151016
ReturnTypeBreakingStyle AlwaysBreakAfterReturnType;
10161017

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

1580+
/// The function declaration return type breaking style to use.
1581+
/// \version 19
1582+
// ReturnTypeBreakingStyle BreakAfterReturnType;
1583+
15791584
/// If ``true``, clang-format will always break after a Json array ``[``
15801585
/// otherwise it will scan until the closing ``]`` to determine if it should
15811586
/// add newlines between elements (prettier compatible).

clang/lib/Format/Format.cpp

Lines changed: 3 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("AlwaysBreakAfterReturnType",
881+
Style.AlwaysBreakAfterReturnType);
880882
IO.mapOptional("AlwaysBreakTemplateDeclarations",
881883
Style.BreakTemplateDeclarations);
882884
IO.mapOptional("BreakBeforeInheritanceComma",
@@ -941,8 +943,6 @@ template <> struct MappingTraits<FormatStyle> {
941943
Style.AllowShortLoopsOnASingleLine);
942944
IO.mapOptional("AlwaysBreakAfterDefinitionReturnType",
943945
Style.AlwaysBreakAfterDefinitionReturnType);
944-
IO.mapOptional("AlwaysBreakAfterReturnType",
945-
Style.AlwaysBreakAfterReturnType);
946946
IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
947947
Style.AlwaysBreakBeforeMultilineStrings);
948948
IO.mapOptional("AttributeMacros", Style.AttributeMacros);
@@ -957,6 +957,7 @@ template <> struct MappingTraits<FormatStyle> {
957957
IO.mapOptional("BreakAfterAttributes", Style.BreakAfterAttributes);
958958
IO.mapOptional("BreakAfterJavaFieldAnnotations",
959959
Style.BreakAfterJavaFieldAnnotations);
960+
IO.mapOptional("BreakAfterReturnType", Style.AlwaysBreakAfterReturnType);
960961
IO.mapOptional("BreakArrays", Style.BreakArrays);
961962
IO.mapOptional("BreakBeforeBinaryOperators",
962963
Style.BreakBeforeBinaryOperators);

clang/unittests/Format/ConfigParseTest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,22 @@ TEST(ConfigParseTest, ParsesConfiguration) {
678678
BraceWrapping.AfterControlStatement, FormatStyle::BWACS_Never);
679679

680680
Style.AlwaysBreakAfterReturnType = FormatStyle::RTBS_All;
681+
CHECK_PARSE("BreakAfterReturnType: None", AlwaysBreakAfterReturnType,
682+
FormatStyle::RTBS_None);
683+
CHECK_PARSE("BreakAfterReturnType: Automatic", AlwaysBreakAfterReturnType,
684+
FormatStyle::RTBS_Automatic);
685+
CHECK_PARSE("BreakAfterReturnType: ExceptShortType",
686+
AlwaysBreakAfterReturnType, FormatStyle::RTBS_ExceptShortType);
687+
CHECK_PARSE("BreakAfterReturnType: All", AlwaysBreakAfterReturnType,
688+
FormatStyle::RTBS_All);
689+
CHECK_PARSE("BreakAfterReturnType: TopLevel", AlwaysBreakAfterReturnType,
690+
FormatStyle::RTBS_TopLevel);
691+
CHECK_PARSE("BreakAfterReturnType: AllDefinitions",
692+
AlwaysBreakAfterReturnType, FormatStyle::RTBS_AllDefinitions);
693+
CHECK_PARSE("BreakAfterReturnType: TopLevelDefinitions",
694+
AlwaysBreakAfterReturnType,
695+
FormatStyle::RTBS_TopLevelDefinitions);
696+
// For backward compatibility:
681697
CHECK_PARSE("AlwaysBreakAfterReturnType: None", AlwaysBreakAfterReturnType,
682698
FormatStyle::RTBS_None);
683699
CHECK_PARSE("AlwaysBreakAfterReturnType: Automatic",

0 commit comments

Comments
 (0)