From patchwork Wed Aug 31 13:39:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 868 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp235832wro; Wed, 31 Aug 2022 06:40:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR6s0z2CJK2PZB9aOudk0LaSiSPE4VBjlLfVAbC+UkgQH+p3FDvdpiqABKgZXiDnLEqyIZcJ X-Received: by 2002:a17:906:58c8:b0:6fe:91d5:18d2 with SMTP id e8-20020a17090658c800b006fe91d518d2mr20724491ejs.190.1661953253993; Wed, 31 Aug 2022 06:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661953253; cv=none; d=google.com; s=arc-20160816; b=s3rC/5e6V64eApJlYX9mteaqnbSnd4D0VAJwpNih1aOie9gAah+hk+ymXIty5uokDr IwhM/KV/QeNIX3OY6SlQ7qH74MCovq2gsYrV8fZbyFVbT6L4ddH9VSaqvmScduS1VK8d /D22dOKbC0lFFsW8njuQ6TjHxLCN/vihAYXCV/tJBrxqlPiX0VCtPLNswwXiykXP7f/n 5akK+xf7Ml+zpmdOdJyItm0ekbdgkxQ7xsLKUwIgNi/MJWd2SJysyghBT8NbiNtKR5Qf jwT1tLilp6uBPGZNnYfaFXfb2F5qPvxMwGwW1dKiMT/jMp6qB57nubFRSfnIi4Jl965M WI7g== 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=gLW+57xRnW+xD3PO4JUjUIyhzlQ3f/eSvstvGTayDPs=; b=DodAmAdkfvkxzLuY/qJDPcqtJITmyzzwpZ9xj+FGMkJOZ/ioh7nWne3m0q2Na/1JoY 5QSDz7kTMR1WLoYhv9ySgVwmBhP+tya9YKvFoh5NPUVdDGqYgMj5p/YxANDCgIk8wUke JvqsTdcm5/Ol9mw5qWNTkuzQ3Mzv6uofwR3JqkpSq6JpbAvZ4ioldW6+14/En0fBw0Ck jU/B1txS3HYSBNLEgjr0MLiExyDfCsI5lXcwz6I8y102fXPWSsd+0wv5w6a4zZ4uP4Xo ZBlcbh7YLR+V2Nuhqwp9c5ia9//8yVNG03LfJ1MFcWw0DSc6ujVP758vCJn+Qmisflwr 5lpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=jR8GTcS2; 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 j11-20020a05640211cb00b00447726f8e2asi12884150edw.48.2022.08.31.06.40.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 06:40:53 -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=jR8GTcS2; 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 4AC7638233E1 for ; Wed, 31 Aug 2022 13:39:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4AC7638233E1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661953189; bh=gLW+57xRnW+xD3PO4JUjUIyhzlQ3f/eSvstvGTayDPs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jR8GTcS2JuvUbzORRyUNXTq12fEAGJeQNcSw7g7193fK692K4mmFIXrr+lWLsUc3x pjxULH6/bxp1rem1Qkgf4LzMoS0Io5FtpoJvicpiigErlW2BfUbkAL9ZkC3KAbex6/ LI1J5BMfWj+lxN0auxMbGzLwPZU96ftp5rj5c++g= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 3E7BF3853540 for ; Wed, 31 Aug 2022 13:39:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3E7BF3853540 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) 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 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=unavailable 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?1742684295162201264?= X-GMAIL-MSGID: =?utf-8?q?1742684295162201264?= 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)()) );