public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Optimize std::destructible concept
Date: Thu, 10 Nov 2022 02:00:31 +0000	[thread overview]
Message-ID: <20221110020031.152520-1-jwakely@redhat.com> (raw)

Tested x86_64-linux. Pushed to trunk.

-- >8 --

This uses variable templates and constraints to define a much simpler
std::destructible concept. This avoids instantiating the trait
std::is_nothrow_destructible and all its implementation in terms of
__is_destructible_safe and __is_destructible_impl.

If we had an intrinsic we could just use that (PR c++/107600).

libstdc++-v3/ChangeLog:

	* include/std/concepts (__detail::__destructible_impl)
	(__detail::__destructible): New variable templates.
	(destructible): Use __detail::__destructible.
	* testsuite/std/concepts/concepts.lang/concept.destructible/1.cc:
	Add more checks for array and reference types.
---
 libstdc++-v3/include/std/concepts             | 24 +++++++++++++++----
 .../concepts.lang/concept.destructible/1.cc   |  5 ++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/include/std/concepts b/libstdc++-v3/include/std/concepts
index 32139063936..c062d62d24f 100644
--- a/libstdc++-v3/include/std/concepts
+++ b/libstdc++-v3/include/std/concepts
@@ -113,9 +113,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     template<typename _Tp>
       using __cref = const remove_reference_t<_Tp>&;
 
-      template<typename _Tp>
-	concept __class_or_enum
-	  = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
+    template<typename _Tp>
+      concept __class_or_enum
+	= is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>;
+
+    template<typename _Tp>
+      constexpr bool __destructible_impl = false;
+    template<typename _Tp>
+      requires requires(_Tp& __t) { { __t.~_Tp() } noexcept; }
+      constexpr bool __destructible_impl<_Tp> = true;
+
+    template<typename _Tp>
+      constexpr bool __destructible = __destructible_impl<_Tp>;
+    template<typename _Tp>
+      constexpr bool __destructible<_Tp&> = true;
+    template<typename _Tp>
+      constexpr bool __destructible<_Tp&&> = true;
+    template<typename _Tp, size_t _Nm>
+      constexpr bool __destructible<_Tp[_Nm]> = __destructible<_Tp>;
+
   } // namespace __detail
 
   /// [concept.assignable], concept assignable_from
@@ -129,7 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// [concept.destructible], concept destructible
   template<typename _Tp>
-    concept destructible = is_nothrow_destructible_v<_Tp>;
+    concept destructible = __detail::__destructible<_Tp>;
 
   /// [concept.constructible], concept constructible_from
   template<typename _Tp, typename... _Args>
diff --git a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.destructible/1.cc b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.destructible/1.cc
index a0bd0364d1b..81d72abbdaa 100644
--- a/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.destructible/1.cc
+++ b/libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.destructible/1.cc
@@ -29,6 +29,7 @@ static_assert( std::destructible<int&&> );
 static_assert( std::destructible<const int&> );
 static_assert( !std::destructible<int[]> );
 static_assert( std::destructible<int[2]> );
+static_assert( std::destructible<int[2][3]> );
 static_assert( !std::destructible<int()> );
 static_assert( std::destructible<int(*)()> );
 static_assert( std::destructible<int(&)()> );
@@ -47,6 +48,8 @@ struct C
   ~C() noexcept(false) { }
 };
 static_assert( !std::destructible<C> );
+static_assert( std::destructible<C&> );
+static_assert( !std::destructible<C[1]> );
 class D
 {
 public:
@@ -55,3 +58,5 @@ private:
   ~D() { }
 };
 static_assert( !std::destructible<D> );
+static_assert( std::destructible<D&> );
+static_assert( !std::destructible<D[1]> );
-- 
2.38.1


                 reply	other threads:[~2022-11-10  2:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221110020031.152520-1-jwakely@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).