[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/HazardyKnusperkeks closed https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/HazardyKnusperkeks updated https://github.com/llvm/llvm-project/pull/65808: From 3d3b20f66212f86bd46853432f1be31e5977df83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= Date: Fri, 8 Sep 2023 13:07:09 +0200 Subject: [PATCH] [clang-format] BreakBeforeNoexceptSpecifier option added --- clang/docs/ClangFormatStyleOptions.rst | 48 ++ clang/docs/ReleaseNotes.rst| 1 + clang/include/clang/Format/Format.h| 43 +++ clang/lib/Format/Format.cpp| 14 +++ clang/lib/Format/TokenAnnotator.cpp| 11 + clang/unittests/Format/ConfigParseTest.cpp | 8 clang/unittests/Format/FormatTest.cpp | 46 + 7 files changed, 171 insertions(+) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index df27f6166d37105..44bffa41d1cde95 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -1108,6 +1108,54 @@ the configuration (without a prefix: ``Auto``). int d, int e); +.. _AllowBreakBeforeNoexceptSpecifier: + +**AllowBreakBeforeNoexceptSpecifier** (``BreakBeforeNoexceptSpecifierStyle``) :versionbadge:`clang-format 18` :ref:`¶ ` + Controls if there could be a line break before a ``noexcept`` specifier. + + Possible values: + + * ``BBNSS_Never`` (in configuration: ``Never``) +No line break allowed. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) noexcept( + noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_OnlyWithParen`` (in configuration: ``OnlyWithParen``) +For a simple ``noexcept`` there is no line break allowed, but when we +have a condition it is. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_Always`` (in configuration: ``Always``) +Line breaks are allowed. But note that because of the associated +penalties ``clang-format`` often prefers not to break before the +``noexcept``. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + + .. _AllowShortBlocksOnASingleLine: **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 28a6ec0acd409b0..5c1f7ae54ffe09d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -374,6 +374,7 @@ AST Matchers clang-format +- Add ``AllowBreakBeforeNoexceptSpecifier`` option. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 7ebde3c174d2640..e0444966b3eabc7 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -593,6 +593,47 @@ struct FormatStyle { /// \version 3.3 bool AllowAllParametersOfDeclarationOnNextLine; + /// Different ways to break before a noexcept specifier. + enum BreakBeforeNoexceptSpecifierStyle : int8_t { +/// No line break allowed. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) noexcept( +/// noexcept(baz(arg1)) && +/// noexcept(baz(arg2))); +/// \endcode +BBNSS_Never, +/// For a simple ``noexcept`` there is no line break allowed, but when we +/// have a condition it is. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_OnlyWithParen, +/// Line breaks are allowed. But note that because of the associated +/// penalties ``clang-format`` often prefers not to break before the +/// ``noexcept``. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_Always, + }; + + /// Controls if there could be a line break before a ``noexcept`` specifier. + /// \version 18 + BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier; + /// Different styles for merging short blocks containing at most one /// statement. enum ShortBlockStyle : int8_t { @@ -4576,6 +4617,8 @@ struct FormatStyle { AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
=?utf-8?q?Björn_Schäpers?= llvmbot wrote: @llvm/pr-subscribers-clang-format Changes It really bugs me that it breaks to ``` c++ ...) noexcept( noexcept(condition)... ``` This is a fix for people like me. -- Full diff: https://github.com/llvm/llvm-project/pull/65808.diff 7 Files Affected: - (modified) clang/docs/ClangFormatStyleOptions.rst (+48) - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/include/clang/Format/Format.h (+43) - (modified) clang/lib/Format/Format.cpp (+14) - (modified) clang/lib/Format/TokenAnnotator.cpp (+11) - (modified) clang/unittests/Format/ConfigParseTest.cpp (+8) - (modified) clang/unittests/Format/FormatTest.cpp (+46) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index df27f6166d37105..51e4b2661a9ea84 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -1108,6 +1108,54 @@ the configuration (without a prefix: ``Auto``). int d, int e); +.. _AllowBreakBeforeNoexceptSpecifier: + +**AllowBreakBeforeNoexceptSpecifier** (``BreakBeforeNoexceptSpecifierStyle``) :versionbadge:`clang-format 18` :ref:`¶ ` + Controls if there could be a line break before a ``noexcept`` specifier. + + Possible values: + + * ``BBNSS_Never`` (in configuration: ``Never``) +No line break allowed. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) noexcept( + noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_OnlyWithParen`` (in configuration: ``OnlyWithParen``) +For a simple ``noexcept`` there is no line break allowed, but when we +have a condition it is. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_Always`` (in configuration: ``Always``) +Line breaks are allowed. Bute note that because of the associtated +penalties ``clang-format`` often prefers not to break before the +``noexcept``. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + + .. _AllowShortBlocksOnASingleLine: **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 28a6ec0acd409b0..5c1f7ae54ffe09d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -374,6 +374,7 @@ AST Matchers clang-format +- Add ``AllowBreakBeforeNoexceptSpecifier`` option. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 7ebde3c174d2640..e0444966b3eabc7 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -593,6 +593,47 @@ struct FormatStyle { /// \version 3.3 bool AllowAllParametersOfDeclarationOnNextLine; + /// Different ways to break before a noexcept specifier. + enum BreakBeforeNoexceptSpecifierStyle : int8_t { +/// No line break allowed. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) noexcept( +/// noexcept(baz(arg1)) && +/// noexcept(baz(arg2))); +/// \endcode +BBNSS_Never, +/// For a simple ``noexcept`` there is no line break allowed, but when we +/// have a condition it is. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_OnlyWithParen, +/// Line breaks are allowed. But note that because of the associated +/// penalties ``clang-format`` often prefers not to break before the +/// ``noexcept``. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_Always, + }; + + /// Controls if there could be a line break before a ``noexcept`` specifier. + /// \version 18 + BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier; + /// Different styles for merging short blocks containing at most one /// statement. enum ShortBlockStyle : int8_t { @@ -4576,6 +4617,8 @@ struct FormatStyle { AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine && AllowAllParametersOfDeclarationOnNextLine ==
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
=?utf-8?q?Björn_Schäpers?= llvmbot wrote: @llvm/pr-subscribers-clang Changes It really bugs me that it breaks to ``` c++ ...) noexcept( noexcept(condition)... ``` This is a fix for people like me. -- Full diff: https://github.com/llvm/llvm-project/pull/65808.diff 7 Files Affected: - (modified) clang/docs/ClangFormatStyleOptions.rst (+48) - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/include/clang/Format/Format.h (+43) - (modified) clang/lib/Format/Format.cpp (+14) - (modified) clang/lib/Format/TokenAnnotator.cpp (+11) - (modified) clang/unittests/Format/ConfigParseTest.cpp (+8) - (modified) clang/unittests/Format/FormatTest.cpp (+46) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index df27f6166d37105..51e4b2661a9ea84 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -1108,6 +1108,54 @@ the configuration (without a prefix: ``Auto``). int d, int e); +.. _AllowBreakBeforeNoexceptSpecifier: + +**AllowBreakBeforeNoexceptSpecifier** (``BreakBeforeNoexceptSpecifierStyle``) :versionbadge:`clang-format 18` :ref:`¶ ` + Controls if there could be a line break before a ``noexcept`` specifier. + + Possible values: + + * ``BBNSS_Never`` (in configuration: ``Never``) +No line break allowed. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) noexcept( + noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_OnlyWithParen`` (in configuration: ``OnlyWithParen``) +For a simple ``noexcept`` there is no line break allowed, but when we +have a condition it is. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_Always`` (in configuration: ``Always``) +Line breaks are allowed. Bute note that because of the associtated +penalties ``clang-format`` often prefers not to break before the +``noexcept``. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + + .. _AllowShortBlocksOnASingleLine: **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 28a6ec0acd409b0..5c1f7ae54ffe09d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -374,6 +374,7 @@ AST Matchers clang-format +- Add ``AllowBreakBeforeNoexceptSpecifier`` option. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 7ebde3c174d2640..e0444966b3eabc7 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -593,6 +593,47 @@ struct FormatStyle { /// \version 3.3 bool AllowAllParametersOfDeclarationOnNextLine; + /// Different ways to break before a noexcept specifier. + enum BreakBeforeNoexceptSpecifierStyle : int8_t { +/// No line break allowed. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) noexcept( +/// noexcept(baz(arg1)) && +/// noexcept(baz(arg2))); +/// \endcode +BBNSS_Never, +/// For a simple ``noexcept`` there is no line break allowed, but when we +/// have a condition it is. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_OnlyWithParen, +/// Line breaks are allowed. But note that because of the associated +/// penalties ``clang-format`` often prefers not to break before the +/// ``noexcept``. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_Always, + }; + + /// Controls if there could be a line break before a ``noexcept`` specifier. + /// \version 18 + BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier; + /// Different styles for merging short blocks containing at most one /// statement. enum ShortBlockStyle : int8_t { @@ -4576,6 +4617,8 @@ struct FormatStyle { AllowAllArgumentsOnNextLine == R.AllowAllArgumentsOnNextLine && AllowAllParametersOfDeclarationOnNextLine ==
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
=?utf-8?q?Björn_Schäpers?= https://github.com/llvmbot labeled https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
=?utf-8?q?Björn_Schäpers?= https://github.com/llvmbot labeled https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/HazardyKnusperkeks updated https://github.com/llvm/llvm-project/pull/65808: From d0415b4436a11e649fbeae53b8060f70bae03254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= Date: Fri, 8 Sep 2023 13:07:09 +0200 Subject: [PATCH 1/2] [clang-format] BreakBeforeNoexceptSpecifier option added --- clang/docs/ClangFormatStyleOptions.rst | 48 ++ clang/docs/ReleaseNotes.rst| 1 + clang/include/clang/Format/Format.h| 43 +++ clang/lib/Format/Format.cpp| 14 +++ clang/lib/Format/TokenAnnotator.cpp| 11 + clang/unittests/Format/ConfigParseTest.cpp | 8 clang/unittests/Format/FormatTest.cpp | 46 + 7 files changed, 171 insertions(+) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index df27f6166d37105..51e4b2661a9ea84 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -1108,6 +1108,54 @@ the configuration (without a prefix: ``Auto``). int d, int e); +.. _AllowBreakBeforeNoexceptSpecifier: + +**AllowBreakBeforeNoexceptSpecifier** (``BreakBeforeNoexceptSpecifierStyle``) :versionbadge:`clang-format 18` :ref:`¶ ` + Controls if there could be a line break before a ``noexcept`` specifier. + + Possible values: + + * ``BBNSS_Never`` (in configuration: ``Never``) +No line break allowed. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) noexcept( + noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_OnlyWithParen`` (in configuration: ``OnlyWithParen``) +For a simple ``noexcept`` there is no line break allowed, but when we +have a condition it is. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_Always`` (in configuration: ``Always``) +Line breaks are allowed. Bute note that because of the associtated +penalties ``clang-format`` often prefers not to break before the +``noexcept``. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + + .. _AllowShortBlocksOnASingleLine: **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 28a6ec0acd409b0..5c1f7ae54ffe09d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -374,6 +374,7 @@ AST Matchers clang-format +- Add ``AllowBreakBeforeNoexceptSpecifier`` option. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 7ebde3c174d2640..51c17bb214b678b 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -593,6 +593,47 @@ struct FormatStyle { /// \version 3.3 bool AllowAllParametersOfDeclarationOnNextLine; + /// Different ways to break before a noexcept specifier. + enum BreakBeforeNoexceptSpecifierStyle : int8_t { +/// No line break allowed. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) noexcept( +/// noexcept(baz(arg1)) && +/// noexcept(baz(arg2))); +/// \endcode +BBNSS_Never, +/// For a simple ``noexcept`` there is no line break allowed, but when we +/// have a condition it is. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_OnlyWithParen, +/// Line breaks are allowed. Bute note that because of the associtated +/// penalties ``clang-format`` often prefers not to break before the +/// ``noexcept``. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_Always, + }; + + /// Controls if there could be a line break before a ``noexcept`` specifier. + /// \version 18 + BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier; + /// Different styles for merging short blocks containing at most one /// statement. enum ShortBlockStyle : int8_t { @@ -4576,6 +4617,8 @@ struct FormatStyle { AllowAllArgumentsOnNextLine ==
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/HazardyKnusperkeks resolved https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
@@ -593,6 +593,47 @@ struct FormatStyle { /// \version 3.3 bool AllowAllParametersOfDeclarationOnNextLine; + /// Different ways to break before a noexcept specifier. + enum BreakBeforeNoexceptSpecifierStyle : int8_t { +/// No line break allowed. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) noexcept( +/// noexcept(baz(arg1)) && +/// noexcept(baz(arg2))); +/// \endcode +BBNSS_Never, +/// For a simple ``noexcept`` there is no line break allowed, but when we +/// have a condition it is. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_OnlyWithParen, +/// Line breaks are allowed. Bute note that because of the associtated rymiel wrote: ```suggestion /// Line breaks are allowed. But note that because of the associated ``` https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/rymiel approved this pull request. https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/rymiel edited https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/HazardyKnusperkeks created https://github.com/llvm/llvm-project/pull/65808: It really bugs me that it breaks to ``` c++ ...) noexcept( noexcept(condition)... ``` This is a fix for people like me. From d0415b4436a11e649fbeae53b8060f70bae03254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= Date: Fri, 8 Sep 2023 13:07:09 +0200 Subject: [PATCH] [clang-format] BreakBeforeNoexceptSpecifier option added --- clang/docs/ClangFormatStyleOptions.rst | 48 ++ clang/docs/ReleaseNotes.rst| 1 + clang/include/clang/Format/Format.h| 43 +++ clang/lib/Format/Format.cpp| 14 +++ clang/lib/Format/TokenAnnotator.cpp| 11 + clang/unittests/Format/ConfigParseTest.cpp | 8 clang/unittests/Format/FormatTest.cpp | 46 + 7 files changed, 171 insertions(+) diff --git a/clang/docs/ClangFormatStyleOptions.rst b/clang/docs/ClangFormatStyleOptions.rst index df27f6166d37105..51e4b2661a9ea84 100644 --- a/clang/docs/ClangFormatStyleOptions.rst +++ b/clang/docs/ClangFormatStyleOptions.rst @@ -1108,6 +1108,54 @@ the configuration (without a prefix: ``Auto``). int d, int e); +.. _AllowBreakBeforeNoexceptSpecifier: + +**AllowBreakBeforeNoexceptSpecifier** (``BreakBeforeNoexceptSpecifierStyle``) :versionbadge:`clang-format 18` :ref:`¶ ` + Controls if there could be a line break before a ``noexcept`` specifier. + + Possible values: + + * ``BBNSS_Never`` (in configuration: ``Never``) +No line break allowed. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) noexcept( + noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_OnlyWithParen`` (in configuration: ``OnlyWithParen``) +For a simple ``noexcept`` there is no line break allowed, but when we +have a condition it is. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + * ``BBNSS_Always`` (in configuration: ``Always``) +Line breaks are allowed. Bute note that because of the associtated +penalties ``clang-format`` often prefers not to break before the +``noexcept``. + +.. code-block:: c++ + + void foo(int arg1, + double arg2) noexcept; + + void bar(int arg1, double arg2) + noexcept(noexcept(baz(arg1)) && + noexcept(baz(arg2))); + + + .. _AllowShortBlocksOnASingleLine: **AllowShortBlocksOnASingleLine** (``ShortBlockStyle``) :versionbadge:`clang-format 3.5` :ref:`¶ ` diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 28a6ec0acd409b0..5c1f7ae54ffe09d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -374,6 +374,7 @@ AST Matchers clang-format +- Add ``AllowBreakBeforeNoexceptSpecifier`` option. libclang diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 7ebde3c174d2640..51c17bb214b678b 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -593,6 +593,47 @@ struct FormatStyle { /// \version 3.3 bool AllowAllParametersOfDeclarationOnNextLine; + /// Different ways to break before a noexcept specifier. + enum BreakBeforeNoexceptSpecifierStyle : int8_t { +/// No line break allowed. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) noexcept( +/// noexcept(baz(arg1)) && +/// noexcept(baz(arg2))); +/// \endcode +BBNSS_Never, +/// For a simple ``noexcept`` there is no line break allowed, but when we +/// have a condition it is. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_OnlyWithParen, +/// Line breaks are allowed. Bute note that because of the associtated +/// penalties ``clang-format`` often prefers not to break before the +/// ``noexcept``. +/// \code +/// void foo(int arg1, +///double arg2) noexcept; +/// +/// void bar(int arg1, double arg2) +/// noexcept(noexcept(baz(arg1)) && +///noexcept(baz(arg2))); +/// \endcode +BBNSS_Always, + }; + + /// Controls if there could be a line break before a ``noexcept`` specifier. + /// \version 18 + BreakBeforeNoexceptSpecifierStyle AllowBreakBeforeNoexceptSpecifier; + /// Different styles for merging short blocks containing at most one /// statement. enum
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/HazardyKnusperkeks review_requested https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] BreakBeforeNoexceptSpecifier option added (PR #65808)
https://github.com/HazardyKnusperkeks review_requested https://github.com/llvm/llvm-project/pull/65808 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits