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 75B4F383E041 for ; Wed, 31 Aug 2022 13:39:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 75B4F383E041 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=1661953144; 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=gLW+57xRnW+xD3PO4JUjUIyhzlQ3f/eSvstvGTayDPs=; b=egz+8c7iMPdk8Y5ijM5B+IhRfLGx24Ezzc/13/N+5vJvXrBZc6NwNciU0Ls11BFdgC7nHq Dm/xmPO19uAl5un/+PJoTL351Tao94TYlqMAZ8GXbQqA6x/u0sId5eCOPPRnXBWd+a6Exe CxWEnvWAx2w8odY2Hs+Klqx5W9gaiTo= 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-401-Tnt1i5E6MNu7Cd5tLM7eiw-1; Wed, 31 Aug 2022 09:39:02 -0400 X-MC-Unique: Tnt1i5E6MNu7Cd5tLM7eiw-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 654C83C1014A; Wed, 31 Aug 2022 13:39:02 +0000 (UTC) Received: from localhost (unknown [10.33.36.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B0A12166B26; Wed, 31 Aug 2022 13:39:02 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add noexcept-specifier to std::reference_wrapper::operator() Date: Wed, 31 Aug 2022 14:39:01 +0100 Message-Id: <20220831133901.63261-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 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=-12.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_LOW,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 isn't required by the standard, but there's an LWG issue suggesting to add it. Also use __invoke_result instead of result_of, to match the spec in recent standards. libstdc++-v3/ChangeLog: * include/bits/refwrap.h (reference_wrapper::operator()): Add noexcept-specifier and use __invoke_result instead of result_of. * testsuite/20_util/reference_wrapper/invoke-noexcept.cc: New test. --- libstdc++-v3/include/bits/refwrap.h | 3 ++- .../20_util/reference_wrapper/invoke-noexcept.cc | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc diff --git a/libstdc++-v3/include/bits/refwrap.h b/libstdc++-v3/include/bits/refwrap.h index 8016f87478e..976902bc7bc 100644 --- a/libstdc++-v3/include/bits/refwrap.h +++ b/libstdc++-v3/include/bits/refwrap.h @@ -348,8 +348,9 @@ _GLIBCXX_MEM_FN_TRAITS(&& noexcept, false_type, true_type) template _GLIBCXX20_CONSTEXPR - typename result_of<_Tp&(_Args&&...)>::type + typename __invoke_result<_Tp&, _Args...>::type operator()(_Args&&... __args) const + noexcept(__is_nothrow_invocable<_Tp&, _Args...>::value) { #if __cplusplus > 201703L if constexpr (is_object_v) diff --git a/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc new file mode 100644 index 00000000000..91b5d097f08 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/reference_wrapper/invoke-noexcept.cc @@ -0,0 +1,15 @@ +// { dg-do compile { target c++11 } } + +// C++11 20.8.3.4 reference_wrapper invocation [refwrap.invoke] + +#include + +struct F +{ + int operator()() noexcept(true) { return 1; } + int operator()() const noexcept(false) { return 2; } +}; + +F f; +static_assert( noexcept(std::ref(f)()) ); +static_assert( ! noexcept(std::cref(f)()) ); -- 2.37.2