-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
Drop the "Always" prefix to remove the self-contradiction.
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesDrop the "Always" prefix to remove the self-contradiction. Full diff: https://github.com/llvm/llvm-project/pull/81093.diff 5 Files Affected:
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 0a8cc18c5b4cb5..f3da652e691451 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -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:
@@ -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>`
diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index e41891f07de2e3..203e9450ed3767 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -308,6 +308,7 @@ class State:
enum = None
nested_struct = None
version = None
+ deprecated = False
for line in self.header:
self.lineno += 1
@@ -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"):
@@ -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)
@@ -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]
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index cb14d98825400b..b4969aa2b6fbe1 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -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
@@ -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
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c5714af155f0b5..c5a89490e9287d 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("AlwaysBreakTemplateDeclarations",
+ Style.AlwaysBreakTemplateDeclarations);
IO.mapOptional("BreakBeforeInheritanceComma",
BreakBeforeInheritanceComma);
IO.mapOptional("BreakConstructorInitializersBeforeComma",
@@ -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);
@@ -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);
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 7493b0a4450f9b..22681a2ac8a3ee 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -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",
|
@llvm/pr-subscribers-clang Author: Owen Pan (owenca) ChangesDrop the "Always" prefix to remove the self-contradiction. Full diff: https://github.com/llvm/llvm-project/pull/81093.diff 5 Files Affected:
diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst
index 0a8cc18c5b4cb5..f3da652e691451 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -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:
@@ -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>`
diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py
index e41891f07de2e3..203e9450ed3767 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -308,6 +308,7 @@ class State:
enum = None
nested_struct = None
version = None
+ deprecated = False
for line in self.header:
self.lineno += 1
@@ -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"):
@@ -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)
@@ -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]
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index cb14d98825400b..b4969aa2b6fbe1 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -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
@@ -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
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index c5714af155f0b5..c5a89490e9287d 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("AlwaysBreakTemplateDeclarations",
+ Style.AlwaysBreakTemplateDeclarations);
IO.mapOptional("BreakBeforeInheritanceComma",
BreakBeforeInheritanceComma);
IO.mapOptional("BreakConstructorInitializersBeforeComma",
@@ -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);
@@ -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);
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 7493b0a4450f9b..22681a2ac8a3ee 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -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",
|
✅ With the latest revision this PR passed the Python code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go contrary to your comment and rename the attribute. Because otherwise you still have the contradiction within the code.
I was not against renaming the attribute there. I just wanted it to be done in a separate NFC patch. |
Drop the "Always" prefix to remove the self-contradiction.