From patchwork Tue Jun 8 14:01:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1489452 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=api9byOc; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzsPN7484z9sRN for ; Wed, 9 Jun 2021 00:02:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A649395541F for ; Tue, 8 Jun 2021 14:02:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A649395541F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623160932; bh=BuCBZtN/+g1Keg4+7A2I0qsNP8SQitXJ9MGJT7q0Msc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=api9byOccfecXEyS5JvNDBuF5M3/+ewfiqDT+3a16WurKLWmB3Nd3waByXQ0v8KRu yCACMGB5msgBN99F2YecB7qIjLQRSkKfl2VWZYo2+OHFo7JHwLcoIV/2/QEpC3J1eX dnxNryNHkdHtVJmGCPjAMz0pGEEyeZ5XNCSeENr8= 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 ESMTP id 14A68395444C for ; Tue, 8 Jun 2021 14:01:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14A68395444C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-98--37WtJr7OZGixbq5rpePBQ-1; Tue, 08 Jun 2021 10:01:28 -0400 X-MC-Unique: -37WtJr7OZGixbq5rpePBQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10217107ACED; Tue, 8 Jun 2021 14:01:27 +0000 (UTC) Received: from localhost (unknown [10.33.37.1]) by smtp.corp.redhat.com (Postfix) with ESMTP id B27895B826; Tue, 8 Jun 2021 14:01:26 +0000 (UTC) Date: Tue, 8 Jun 2021 15:01:25 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Finish implementing LWG 3413 for propagate_const Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.0 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" We already have conditional noexcept so this just constrains the non-member swap overload. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/experimental/propagate_const (swap): Constrain. * testsuite/experimental/propagate_const/swap/lwg3413.cc: New test. Tested x86_64-linux. Committed to trunk. commit d319517e809ee50496db29e552f86a83a14c837c Author: Jonathan Wakely Date: Tue Jun 8 14:56:57 2021 libstdc++: Finish implementing LWG 3413 for propagate_const We already have conditional noexcept so this just constrains the non-member swap overload. Signed-off-by: Jonathan Wakely libstdc++-v3/ChangeLog: * include/experimental/propagate_const (swap): Constrain. * testsuite/experimental/propagate_const/swap/lwg3413.cc: New test. diff --git a/libstdc++-v3/include/experimental/propagate_const b/libstdc++-v3/include/experimental/propagate_const index 0d03c13c5e1..162b4783dd7 100644 --- a/libstdc++-v3/include/experimental/propagate_const +++ b/libstdc++-v3/include/experimental/propagate_const @@ -113,6 +113,7 @@ inline namespace fundamentals_v2 constexpr propagate_const() = default; propagate_const(const propagate_const& __p) = delete; constexpr propagate_const(propagate_const&& __p) = default; + template , is_convertible<_Up&&, _Tp>>::value, bool @@ -120,6 +121,7 @@ inline namespace fundamentals_v2 constexpr propagate_const(propagate_const<_Up>&& __pu) : _M_t(std::move(get_underlying(__pu))) {} + template , __not_>>::value, @@ -127,6 +129,7 @@ inline namespace fundamentals_v2 constexpr explicit propagate_const(propagate_const<_Up>&& __pu) : _M_t(std::move(get_underlying(__pu))) {} + template , is_convertible<_Up&&, _Tp>, @@ -136,6 +139,7 @@ inline namespace fundamentals_v2 constexpr propagate_const(_Up&& __u) : _M_t(std::forward<_Up>(__u)) {} + template , __not_>, @@ -399,8 +403,10 @@ inline namespace fundamentals_v2 } // [propagate_const.algorithms], specialized algorithms + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 3413. propagate_const's swap [...] needs to be constrained and use a trait template - constexpr void + constexpr enable_if_t<__is_swappable<_Tp>::value, void> swap(propagate_const<_Tp>& __pt, propagate_const<_Tp>& __pt2) noexcept(__is_nothrow_swappable<_Tp>::value) { diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/swap/lwg3413.cc b/libstdc++-v3/testsuite/experimental/propagate_const/swap/lwg3413.cc new file mode 100644 index 00000000000..8dc13cfebdd --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/swap/lwg3413.cc @@ -0,0 +1,41 @@ +// { dg-do compile { target c++14 } } + +// LWG 3413 +// propagate_const's swap's noexcept specification needs to be constrained +// and use a trait + +#include + +using std::experimental::propagate_const; + +propagate_const i; +static_assert( noexcept(i.swap(i)), "member swap is noexcept" ); +static_assert( noexcept(swap(i, i)), "non-member swap is noexcept" ); + +struct P +{ + int i = 0; + int& operator*() const; +}; + +void swap(P&, P&) noexcept(false); + +propagate_const

p; +static_assert( ! noexcept(p.swap(p)), "member swap is conditionally noexcept" ); +static_assert( ! noexcept(swap(p, p)), "non-member swap is conditionally noexcept" ); + +// std::is_swappable not available for -std=c++14 +#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) +struct Q +{ + int i = 0; + int& operator*() const; + + Q& operator=(Q&&) = delete; +}; + +static_assert( ! std::is_swappable::value, "" ); + +static_assert( ! std::is_swappable>::value, + "non-member swap is constrained" ); +#endif