[clang] 91dcf53 - [clang-format] Rename option AlwaysBreakAfterReturnType. (#80827)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 12 20:28:37 PST 2024
Author: rmarker
Date: 2024-02-12T20:28:33-08:00
New Revision: 91dcf53abd34fa836a126c706f87b810d299d802
URL: https://github.com/llvm/llvm-project/commit/91dcf53abd34fa836a126c706f87b810d299d802
DIFF: https://github.com/llvm/llvm-project/commit/91dcf53abd34fa836a126c706f87b810d299d802.diff
LOG: [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.
Added:
Modified:
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/unittests/Format/ConfigParseTest.cpp
Removed:
################################################################################
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 5deeff0db239a8..fdf7bfaeaa4ec7 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -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:
@@ -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>`
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 402a2f8687386c..aa167d75c3bfd1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -296,6 +296,8 @@ clang-format
- ``AlwaysBreakTemplateDeclarations`` is deprecated and renamed to
``BreakTemplateDeclarations``.
+- ``AlwaysBreakAfterReturnType`` is deprecated and renamed to
+ ``BreakAfterReturnType``.
libclang
--------
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index d9c18e5ec1dc30..737cbfced9e9ce 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -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.
@@ -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).
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d2cc466744acbd..8efc42e0576cf9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -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",
@@ -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);
@@ -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);
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 571e1ebda14b76..ee8a55680753f4 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -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",
More information about the cfe-commits
mailing list