From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 774583858D1E for ; Thu, 10 Nov 2022 02:00:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 774583858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668045634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zHAgQ3lIUNtl0tne/4FMU3c6woJJSF2jWZn7D4jjAIQ=; b=djd6615PYCbL8ZbVJ77xGfn937POBXIBHr1oZcvTxwueL+2I0iyRn+5+BHVot6nohSRZyL ORhQDOb23OcWldSjs+vleyy4qEePXR3Ghx6Ri+C/CeVfjuiYLe75Kvt1It4q6VLOYYvA4M anAUS3V96sy5md7ltH2/D7sUudbxFrA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-QFIMvgvvM4C1zrg3AlWrUg-1; Wed, 09 Nov 2022 21:00:32 -0500 X-MC-Unique: QFIMvgvvM4C1zrg3AlWrUg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58BE785A583; Thu, 10 Nov 2022 02:00:32 +0000 (UTC) Received: from localhost (unknown [10.33.36.199]) by smtp.corp.redhat.com (Postfix) with ESMTP id 225D62166B29; Thu, 10 Nov 2022 02:00:32 +0000 (UTC) From: Jonathan Wakely 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 Message-Id: <20221110020031.152520-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 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 ); -- 2.38.1