From patchwork Sat Sep 24 00:07:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp469221wrt; Fri, 23 Sep 2022 17:09:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4tm0FI3Q1oVf8OaQYF1b2sZ6In386KfTls9/YfpX6ARY9wb5p0X6UIsjMqDrnVE0Y2R2dJ X-Received: by 2002:a05:6402:35cb:b0:451:6a0a:6688 with SMTP id z11-20020a05640235cb00b004516a0a6688mr10976762edc.415.1663978159214; Fri, 23 Sep 2022 17:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663978159; cv=none; d=google.com; s=arc-20160816; b=QQg1Km4njefg7Tk7sJiooAayWolNY9z/xwZSb6D0EhqPfBxzdj17NiPe+8loLpdl5j LCAj3e5KVNubK+v9LAMXV0inJKQe5D8xkqnjNhR5QNyyBVUSm0YTaoNEanPm8vOg7dUj 0IrIUdAhjPMX/ehxnK3lTA11wAxiGvPkEuGDMGsCo9inl/bTyul8YhTexD0VPTenAQ4T UejbajwgLXHBQeZenc+cQFheEZYrVcgbVYIypOpAT0v/8kKZoH0Tv8jQZ3d/ST9WJCO6 Hl5RQLJaEOx4YzRHG4sGJ5cNisHpLi0zcwk7rpNAvGRRYtNhJCiMCQALhfc1P0WLrSnb 9Ejg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=FPV6hco7di4N9uQSBhJV+oUyrtoGb4uPjzTIZ3yd6mA=; b=NHskcLWPAGub3o9WFv1FoqBBGCpiAI2s3eAaQx1nOwuscuz/HAibCnvVmNMaQkZpXI egZePJP+mSOxZxfK30i+lacScJhL+EvujtZZnjuPIEprO++UwjhLrZBrxfshfjIfeJ84 lwNktcGg7bCN0jMxHrpJsGSWgys4g8a+PPjnDjCpWn1rYp0peTeLfprgBKWH9vphLubZ kX9Xrwi7hSHL8uqtK0e1gXi+47k4xxfAcJnQ5yt+l0AW1sYNNxF9G0l4Dwz/i6aHxCCZ lmARA2EecDhoqUEStup1HXG9cQb5pjkHUww0oRtHjA9UPXOc5GHPfTKcyOpXra923bMh G78Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wW9mw0kK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i7-20020a0564020f0700b00454532fa864si9108261eda.459.2022.09.23.17.09.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 17:09:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wW9mw0kK; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4D4A3857814 for ; Sat, 24 Sep 2022 00:08:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4D4A3857814 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663978122; bh=FPV6hco7di4N9uQSBhJV+oUyrtoGb4uPjzTIZ3yd6mA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wW9mw0kKiUoxZYiUQY3ZfK2bTr1ThILo8oWC07If/5I5Ye1gIH6MmNWa++unOtLAH 3wSRE8t5CDawYq/R+JMLdWlOUCRifp7KpSrR7UNntPTwWSYLSN65+4hc+H0ShvPW1V Xzuuog0E/i25eRbGpN0bp5JSZRlmosEoH7t141xM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D78953858429 for ; Sat, 24 Sep 2022 00:07:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D78953858429 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-OZrmJsMiPf2R32u-LNlmwQ-1; Fri, 23 Sep 2022 20:07:48 -0400 X-MC-Unique: OZrmJsMiPf2R32u-LNlmwQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9F2213806738; Sat, 24 Sep 2022 00:07:48 +0000 (UTC) Received: from localhost (unknown [10.33.36.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62F29477F55; Sat, 24 Sep 2022 00:07:48 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix std::is_nothrow_invocable_r for uncopyable prvalues [PR91456] Date: Sat, 24 Sep 2022 01:07:47 +0100 Message-Id: <20220924000747.1717312-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1744807562418911109?= X-GMAIL-MSGID: =?utf-8?q?1744807562418911109?= Tested powerpc64le-linux. Pushed to trunk. -- >8 -- This is the last missing piece of PR 91456. This also removes the only use of the C++11 version of std::is_nothrow_invocable, which was just renamed to __is_nothrow_invocable_lib. We can remove that now. libstdc++-v3/ChangeLog: PR libstdc++/91456 * include/std/type_traits (__is_nothrow_invocable_lib): Remove. (__is_invocable_impl::__nothrow_type): New member type which checks if the conversion can throw. (__is_nt_invocable_impl): Replace class template with alias template to __is_nt_invocable_impl::__nothrow_type. * testsuite/20_util/is_nothrow_invocable/91456.cc: New test. * testsuite/20_util/is_nothrow_convertible/value.cc: Remove macro used by value_ext.cc test. * testsuite/20_util/is_nothrow_convertible/value_ext.cc: Remove test for non-standard __is_nothrow_invocable_lib trait. --- libstdc++-v3/include/std/type_traits | 45 ++++++++++--------- .../20_util/is_nothrow_convertible/value.cc | 2 - .../91456.cc} | 19 +++++--- 3 files changed, 36 insertions(+), 30 deletions(-) rename libstdc++-v3/testsuite/20_util/{is_nothrow_convertible/value_ext.cc => is_nothrow_invocable/91456.cc} (59%) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 1797b9e97f7..7c635313a95 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1451,12 +1451,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; #pragma GCC diagnostic pop - // is_nothrow_convertible for C++11 - template - struct __is_nothrow_convertible_lib - : public __is_nt_convertible_helper<_From, _To>::type - { }; - #if __cplusplus > 201703L #define __cpp_lib_is_nothrow_convertible 201806L /// is_nothrow_convertible @@ -2825,7 +2819,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // The primary template is used for invalid INVOKE expressions. template::value, typename = void> - struct __is_invocable_impl : false_type { }; + struct __is_invocable_impl + : false_type + { + using __nothrow_type = false_type; // For is_nothrow_invocable_r + }; // Used for valid INVOKE and INVOKE expressions. template @@ -2833,7 +2831,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /* is_void<_Ret> = */ true, __void_t> : true_type - { }; + { + using __nothrow_type = true_type; // For is_nothrow_invocable_r + }; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wctor-dtor-privacy" @@ -2845,23 +2845,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { private: // The type of the INVOKE expression. - // Unlike declval, this doesn't add_rvalue_reference. - static typename _Result::type _S_get(); + // Unlike declval, this doesn't add_rvalue_reference, so it respects + // guaranteed copy elision. + static typename _Result::type _S_get() noexcept; template - static void _S_conv(_Tp); + static void _S_conv(_Tp) noexcept; // This overload is viable if INVOKE(f, args...) can convert to _Tp. - template(_S_get()))> - static true_type + template(_S_get())), + bool _Noex = noexcept(_S_conv<_Tp>(_S_get()))> + static __bool_constant<_Check_Noex ? _Noex : true> _S_test(int); - template + template static false_type _S_test(...); public: + // For is_invocable_r using type = decltype(_S_test<_Ret>(1)); + + // For is_nothrow_invocable_r + using __nothrow_type = decltype(_S_test<_Ret, true>(1)); }; #pragma GCC diagnostic pop @@ -2992,15 +2999,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; /// @cond undocumented - template - struct __is_nt_invocable_impl : false_type { }; - template - struct __is_nt_invocable_impl<_Result, _Ret, - __void_t> - : __or_, - __is_nothrow_convertible_lib>::type - { }; + using __is_nt_invocable_impl + = typename __is_invocable_impl<_Result, _Ret>::__nothrow_type; /// @endcond /// std::is_nothrow_invocable_r diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value.cc index e9aded73624..a2686285052 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value.cc @@ -21,9 +21,7 @@ #include #include -#ifndef IS_NT_CONVERTIBLE_DEFINED using std::is_nothrow_convertible; -#endif void test01() { diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value_ext.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/91456.cc similarity index 59% rename from libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value_ext.cc rename to libstdc++-v3/testsuite/20_util/is_nothrow_invocable/91456.cc index d736d2ca260..abbbd1aade4 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_convertible/value_ext.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/91456.cc @@ -15,14 +15,21 @@ // with this library; see the file COPYING3. If not see // . -// { dg-do compile { target c++11 } } +// { dg-do compile { target c++17 } } + +// PR 91456 +// std::function and std::is_invocable_r do not understand guaranteed elision #include -// Test the non-standard __is_nothrow_convertible_lib trait +#include -template - using is_nothrow_convertible = std::__is_nothrow_convertible_lib; +struct Immovable { + Immovable() = default; + Immovable(const Immovable&) = delete; + Immovable& operator=(const Immovable&) = delete; +}; -#define IS_NT_CONVERTIBLE_DEFINED -#include "value.cc" +static_assert(std::is_nothrow_invocable_r_v); +static_assert(std::is_nothrow_invocable_r_v); +static_assert(std::is_nothrow_invocable_r_v);