From patchwork Wed Oct 19 11:57:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 78234 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp207493qge; Wed, 19 Oct 2016 04:58:03 -0700 (PDT) X-Received: by 10.99.116.76 with SMTP id e12mr8860749pgn.20.1476878283211; Wed, 19 Oct 2016 04:58:03 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id t27si23090160pfk.177.2016.10.19.04.58.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 04:58:03 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439011-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439011-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439011-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=DUpODMACfhpkvRMCsC5ZebxmvYcf/M iRcoX8rg4ZqdcaCOnfVkK5jaD/UeeSvimrrsgZr5Er4BwzZKKpw/FCPYBJxcGaBp XfsO13Fh5eTCtCM1oX5WgpluUmgfr88+syX5RxhAZCd6qHs/YeLgxuchovZgeWqU ohYNgf6azUf4g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; s=default; bh=TEtTrGUMPIrmmMjWCRNAFCXya5k=; b=E6MS j232he1hQbcDibPqlfPrqDjF3ax33SVR/dOP+R3moi22bcgkoZv4sYRXk05MoVCP 0yscXxhPs/zCVfV+vUmvKG7GmkzbTO5q/QCwqjNJIQITrxBv+PwPAfYCNE/bwZ70 YuCFU2/HAq/fo4MTtS/UUlrHJwlpzjVEUHYyb9c= Received: (qmail 108418 invoked by alias); 19 Oct 2016 11:57:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 108394 invoked by uid 89); 19 Oct 2016 11:57:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=3914, 2311, 2346, Construction X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Oct 2016 11:57:23 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F3A0C04B319; Wed, 19 Oct 2016 11:57:21 +0000 (UTC) Received: from localhost (ovpn-116-70.ams2.redhat.com [10.36.116.70]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9JBvKbV015419; Wed, 19 Oct 2016 07:57:21 -0400 Date: Wed, 19 Oct 2016 12:57:20 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix std::experimental::shared_ptr SFINAE constraints Message-ID: <20161019115720.GY2922@redhat.com> References: <20161019093513.GW2922@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161019093513.GW2922@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) On 19/10/16 10:35 +0100, Jonathan Wakely wrote: >There are lots of SFINAE checks missing from experimental::shared_ptr, >and we even test that shared_ptr(new derived[1]) works, when >it should be ill-formed. Moar tests! Tested powerpc64le-linux, committed to trunk. commit 9258e632b7810db67cef4e60c5c22bef3571b3bb Author: Jonathan Wakely Date: Wed Oct 19 12:06:31 2016 +0100 Test experimental::shared_ptr construction from other smart pointers * testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc: Add tests for valid and invalid conversions. * testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc: Likewise. diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc index 631212f..0e61a3c 100644 --- a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc @@ -29,10 +29,35 @@ struct A : std::experimental::enable_shared_from_this ~A() { ++destroyed; } }; +struct B : A { }; + // 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] // Construction from unique_ptr +template +constexpr bool constructible() +{ + using std::experimental::shared_ptr; + using std::experimental::is_constructible_v; + using std::unique_ptr; + return is_constructible_v, unique_ptr>; +} + +static_assert( constructible< A, A >(), "A -> A compatible" ); +static_assert( !constructible< A, A[] >(), "A -> A[] not compatible" ); +static_assert( !constructible< A, A[1] >(), "A -> A[1] not compatible" ); +static_assert( !constructible< A[], A >(), "A[] -> A not compatible" ); +static_assert( constructible< A[], A[] >(), "A[] -> A[] compatible" ); +static_assert( !constructible< A[], A[1] >(), "A[] -> A[1] not compatible" ); + +static_assert( constructible< B, A >(), "B -> A compatible" ); +static_assert( !constructible< B, A[] >(), "B -> A[] not compatible" ); +static_assert( !constructible< B, A[1] >(), "B -> A[1] not compatible" ); +static_assert( !constructible< B[], A >(), "B[] -> A not compatible" ); +static_assert( !constructible< B[], A[] >(), "B[] -> A[] not compatible" ); +static_assert( !constructible< B[], A[1] >(), "B[2] -> A[1] not compatible" ); + void test01() { diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc index 71cf583..3436c01 100644 --- a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc @@ -23,11 +23,46 @@ #include struct A { }; +struct B : A { }; // 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] +template +constexpr bool constructible() +{ + using std::experimental::shared_ptr; + using std::experimental::weak_ptr; + using std::experimental::is_constructible_v; + return is_constructible_v, weak_ptr> + && is_constructible_v, const weak_ptr&>; +} + +static_assert( constructible< A, A >(), "A -> A compatible" ); +static_assert( !constructible< A, A[] >(), "A -> A[] not compatible" ); +static_assert( !constructible< A, A[1] >(), "A -> A[1] not compatible" ); +static_assert( !constructible< A[], A >(), "A[] -> A not compatible" ); +static_assert( constructible< A[], A[] >(), "A[] -> A[] compatible" ); +static_assert( !constructible< A[], A[1] >(), "A[] -> A[1] not compatible" ); +static_assert( !constructible< A[1], A >(), "A[1] -> A not compatible" ); +static_assert( constructible< A[1], A[] >(), "A[1] -> A[] compatible" ); +static_assert( constructible< A[1], A[1] >(), "A[1] -> A[1] compatible" ); +static_assert( !constructible< A[2], A[1] >(), "A[2] -> A[1] not compatible" ); + +static_assert( constructible< B, A >(), "B -> A compatible" ); +static_assert( !constructible< B, A[] >(), "B -> A[] not compatible" ); +static_assert( !constructible< B, A[1] >(), "B -> A[1] not compatible" ); +static_assert( !constructible< B[], A >(), "B[] -> A not compatible" ); +static_assert( !constructible< B[], A[] >(), "B[] -> A[] not compatible" ); +static_assert( !constructible< B[], A[1] >(), "B[] -> A[1] not compatible" ); +static_assert( !constructible< B[1], A >(), "B[] -> A not compatible" ); +static_assert( !constructible< B[1], A[] >(), "B[] -> A[] not compatible" ); +static_assert( !constructible< B[1], A[1] >(), "B[] -> A[1] not compatible" ); +static_assert( !constructible< B[2], A[1] >(), "B[2] -> A[1] not compatible" ); + + + // Construction from weak_ptr -int +void test01() { A * a = new A[5]; @@ -39,14 +74,10 @@ test01() VERIFY( a3.get() == a ); VERIFY( a2.use_count() == wa.use_count() ); VERIFY( a3.use_count() == wa.use_count() ); - - return 0; } - int main() { test01(); - return 0; }