diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index 0a8cc18c5b4cb..f3da652e69145 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:`¶ ` - 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 - T foo() { - } - template 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 T foo() { - } - template 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 T foo() { - } - template - T foo(int aaaaaaaaaaaaaaaaaaaaa, - int bbbbbbbbbbbbbbbbbbbbb) { - } - - * ``BTDS_Yes`` (in configuration: ``Yes``) - Always break after template declaration. - - .. code-block:: c++ - - template - T foo() { - } - template - T foo(int aaaaaaaaaaaaaaaaaaaaa, - int bbbbbbbbbbbbbbbbbbbbb) { - } - - +**AlwaysBreakTemplateDeclarations** (``deprecated``) :versionbadge:`clang-format 3.4` :ref:`¶ ` + 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:`¶ ` + 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 + T foo() { + } + template 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 T foo() { + } + template 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 T foo() { + } + template + T foo(int aaaaaaaaaaaaaaaaaaaaa, + int bbbbbbbbbbbbbbbbbbbbb) { + } + + * ``BTDS_Yes`` (in configuration: ``Yes``) + Always break after template declaration. + + .. code-block:: c++ + + template + T foo() { + } + template + T foo(int aaaaaaaaaaaaaaaaaaaaa, + int bbbbbbbbbbbbbbbbbbbbb) { + } + + + .. _ColumnLimit: **ColumnLimit** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 52a48c750fe55..9ac861dc1c3d1 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -276,6 +276,9 @@ AST Matchers clang-format ------------ +- ``AlwaysBreakTemplateDeclarations`` is deprecated and renamed to + ``BreakTemplateDeclarations``. + libclang -------- diff --git a/clang/docs/tools/dump_format_style.py b/clang/docs/tools/dump_format_style.py index e41891f07de2e..af0124b94ecaf 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[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", "std::vector", "std::optional", + "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 cb14d98825400..b4969aa2b6fbe 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 c5714af155f0b..c5a89490e9287 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -877,6 +877,8 @@ template <> struct MappingTraits { 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 { 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 { 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 7493b0a4450f9..22681a2ac8a3e 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",