From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 9C9C93858D3C; Thu, 10 Nov 2022 02:00:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C9C93858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668045616; bh=RTopzzUYd+58oaNuT1tJxulia6PaKwEqyQvFfS10a2E=; h=From:To:Subject:Date:From; b=xxaMuB6G/a1KWZz8Cg6vmhG3jLHC2m8Y3B7i78eMbhSNfcVtlkAruOeDLreuE+C5K bbCZkJCzbQZh73saeSmlDQ5q5oGNd6d3mjWLHl2F0cpa4QKdfe/JxQr7D4bPCmNm4a PB6OrLGROc4II84d3EXoGVyeITXuDjmU2XECBpeM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-3870] libstdc++: Optimize std::destructible concept X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 1cdfd0e5cd5fc1f493d0832ed65d31320f9585b7 X-Git-Newrev: 0cbb756fe9c8e13a743bdcf599481b31bd01ddbc Message-Id: <20221110020016.9C9C93858D3C@sourceware.org> Date: Thu, 10 Nov 2022 02:00:16 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0cbb756fe9c8e13a743bdcf599481b31bd01ddbc commit r13-3870-g0cbb756fe9c8e13a743bdcf599481b31bd01ddbc Author: Jonathan Wakely Date: Thu Nov 10 01:30:45 2022 +0000 libstdc++: Optimize std::destructible concept 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. Diff: --- 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 using __cref = const remove_reference_t<_Tp>&; - template - concept __class_or_enum - = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>; + template + concept __class_or_enum + = is_class_v<_Tp> || is_union_v<_Tp> || is_enum_v<_Tp>; + + template + constexpr bool __destructible_impl = false; + template + requires requires(_Tp& __t) { { __t.~_Tp() } noexcept; } + constexpr bool __destructible_impl<_Tp> = true; + + template + constexpr bool __destructible = __destructible_impl<_Tp>; + template + constexpr bool __destructible<_Tp&> = true; + template + constexpr bool __destructible<_Tp&&> = true; + template + 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 - concept destructible = is_nothrow_destructible_v<_Tp>; + concept destructible = __detail::__destructible<_Tp>; /// [concept.constructible], concept constructible_from template 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 ); static_assert( std::destructible ); static_assert( !std::destructible ); static_assert( std::destructible ); +static_assert( std::destructible ); static_assert( !std::destructible ); static_assert( std::destructible ); static_assert( std::destructible ); @@ -47,6 +48,8 @@ struct C ~C() noexcept(false) { } }; static_assert( !std::destructible ); +static_assert( std::destructible ); +static_assert( !std::destructible ); class D { public: @@ -55,3 +58,5 @@ private: ~D() { } }; static_assert( !std::destructible ); +static_assert( std::destructible ); +static_assert( !std::destructible );