From patchwork Wed Oct 19 09:34:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 78206 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp151082qge; Wed, 19 Oct 2016 02:35:27 -0700 (PDT) X-Received: by 10.99.106.6 with SMTP id f6mr7805806pgc.27.1476869727274; Wed, 19 Oct 2016 02:35:27 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id a6si33097422pay.219.2016.10.19.02.35.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2016 02:35:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-438984-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-438984-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-438984-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=aqMImq4EAHgMFjTqyWUKNbDfiuIXmo tCZ4R7v/yn0ni4YjyKMymjqI4bmqQF2Sj0ZRlG15Cg/iRusqrurBeBEEpRElLPMR CVeRktepPVuUPI8+19t7Se2jSkV9PmEi8XEv0vYU6XVcTtp7czlbs6UFORyUG48W 2BzWHPQmhBnxY= 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=K2My0hGJOuIPQQS3RqyKF6vAT7A=; b=t04H zd3vwI28+qOAdYh3VWPXn4NIXSVtjZ1lzmNoWofQo6u6ntTHGDt/ivaBX6x0nBAt b8YQ8EZ70Vm2SISfy5CCdRKdVt7uZ2HKU/UqCRlMZmpKp4twKObA8hbFfbAc5G0f d8FeLgpho7ZeL8QfzG+VaxKVupnBAFm9rN81Pvw= Received: (qmail 51927 invoked by alias); 19 Oct 2016 09:35:09 -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 51894 invoked by uid 89); 19 Oct 2016 09:35:08 -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=1689, uba 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 09:34:58 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 CE668624B2; Wed, 19 Oct 2016 09:34:56 +0000 (UTC) Received: from localhost (ovpn-116-70.ams2.redhat.com [10.36.116.70]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9J9YtLE010512; Wed, 19 Oct 2016 05:34:56 -0400 Date: Wed, 19 Oct 2016 10:34:55 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] PR77990 refactor unique_ptr to encapsulate tuple Message-ID: <20161019093455.GV2922@redhat.com> References: <20161017133759.GL2922@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161017133759.GL2922@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) On 17/10/16 14:37 +0100, Jonathan Wakely wrote: >We are incorrectly requiring unique_ptr deleters to be copyable here: > > explicit > unique_ptr(pointer __p) noexcept > : _M_t(__p, deleter_type()) > { } > >We could just do: > > explicit > unique_ptr(pointer __p) noexcept > : _M_t() > { std::get<0>(_M_t) = __p; } > >But having to deal directly with the std::tuple inside unique_ptr has >been bothering me for some time. The tuple is used so we get the empty >base-class optimisation for the deleter, but that implementation >detail > >This patch refactors unique_ptr to put the std::tuple member into a >new type which provides named accessors for the tuple elements, so we >can stop using get<0> and get<1>. That new type can also provide a >single-argument constructor to fix the copyable requirement for >deleters. This also removes the code for deducing the pointer type >which is duplciated in unique_ptr and unique_ptr, and while in >the neighbourhood I changed it from old-school SFINAE using overloaded >functions to the new hotness with __void_t<>. > >I intend to commit this to trunk, but on the branches I'll just fix >the constructor as shown above, as it's a smaller change. > > > PR libstdc++/77990 > * include/bits/unique_ptr.h (__uniq_ptr_impl): New type to > encapsulate implementation details. > (unique_ptr::unique_ptr(_Up)): Don't copy deleter object. > (unique_ptr::get, unique_ptr::get_deleter, unique_ptr::release): > Call member functions of implementation object. > (unique_ptr): Likewise. > * python/libstdcxx/v6/printers.py (UniquePointerPrinter): Adjust for > new implementation. > * python/libstdcxx/v6/xmethods.py (UniquePtrGetWorker): Likewise. > * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-error > lines. > * testsuite/20_util/unique_ptr/assign/cv_qual.cc: Likewise. > * testsuite/20_util/unique_ptr/cons/cv_qual.cc: Likewise. > * testsuite/20_util/unique_ptr/cons/77990.cc: New test. > >Tested powerpc64le-linux. Committed to trunk. Here's the smaller patch I'm committing to the branches. commit 81ea53cd80fe7aaa3a323dba58bdb2259d672be3 Author: Jonathan Wakely Date: Wed Oct 19 10:21:58 2016 +0100 PR77990 fix unique_ptr for non-copyable deleters PR libstdc++/77990 * include/bits/unique_ptr.h (unique_ptr::unique_ptr(pointer)): Set pointer member after value-initialization of tuple. * testsuite/20_util/unique_ptr/assign/48635_neg.cc: Adjust dg-errors. * testsuite/20_util/unique_ptr/cons/77990.cc: New test. * testsuite/20_util/unique_ptr/cons/cv_qual.cc: Adjust dg-error. diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index c4a6d2f..8e30287 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -168,9 +168,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ explicit unique_ptr(pointer __p) noexcept - : _M_t(__p, deleter_type()) - { static_assert(!is_pointer::value, - "constructed with null function pointer deleter"); } + : _M_t() + { + std::get<0>(_M_t) = __p; + static_assert(!is_pointer::value, + "constructed with null function pointer deleter"); + } /** Takes ownership of a pointer. * diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc index 16ff8ae..785f9ad 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/assign/48635_neg.cc @@ -43,10 +43,10 @@ void f() std::unique_ptr ud(nullptr, d); ub = std::move(ud); // { dg-error "no match" } ub2 = ud; // { dg-error "no match" } -// { dg-error "no type" "" { target *-*-* } 269 } +// { dg-error "no type" "" { target *-*-* } 272 } std::unique_ptr uba(nullptr, b); std::unique_ptr uda(nullptr, d); uba = std::move(uda); // { dg-error "no match" } -// { dg-error "no type" "" { target *-*-* } 537 } +// { dg-error "no type" "" { target *-*-* } 540 } } diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc new file mode 100644 index 0000000..1acc313 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/77990.cc @@ -0,0 +1,28 @@ +// Copyright (C) 2016 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++11" } +// { dg-do compile } + +#include + +struct D { + D() = default; + D(const D&) = delete; + void operator()(int*); +}; +std::unique_ptr p((int*)nullptr); // PR libstdc++/77990 diff --git a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc index 078ecbb..0f69029 100644 --- a/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc +++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/cv_qual.cc @@ -106,7 +106,7 @@ test07() std::unique_ptr cA3(p); // { dg-error "no matching function" } std::unique_ptr vA3(p); // { dg-error "no matching function" } std::unique_ptr cvA3(p); // { dg-error "no matching function" } - // { dg-error "no type" "" { target *-*-* } 445 } + // { dg-error "no type" "" { target *-*-* } 448 } } template