From patchwork Thu Dec 22 17:11:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 88886 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp2913740qgi; Thu, 22 Dec 2016 09:11:59 -0800 (PST) X-Received: by 10.84.178.195 with SMTP id z61mr21588639plb.176.1482426719685; Thu, 22 Dec 2016 09:11:59 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id q197si31357533pfq.263.2016.12.22.09.11.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Dec 2016 09:11:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444992-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-444992-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444992-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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=aAqzDl+AbMkWvchFt c1M8Xv6fyjSv4tSTm7D9/pe7UFURz18VNIppPOg+F2mEMwARO0WX67MLgWrVWQkZ +SYEMPXe614lai04VuHkfCqPl/gO6caU54dVTNczGnJ7gkz9sDiYaM0yRTVzAZy1 ELoYE9LPcd+d4a7iI5K3bUWTGs= 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:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=YIUlYMQSQNqNLyZ6Kpzjz3Q mXEg=; b=tORfHksqhZhXZPMuFCyNGIThVa4QsoYsoNMnCXh5vznQCf+JBBDj+D8 5pVlWuEuC1XgvCiz+ip8o8X5GQOy6hCsCPnlZKfQsQiq+HyUaaMwQN0AxI6fi2fb cX60xGxCxvoe1Crroh2blFmoNTb1KQ+dc1Ywi80fe4maSg5FRfRw= Received: (qmail 111751 invoked by alias); 22 Dec 2016 17:11:36 -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 111719 invoked by uid 89); 22 Dec 2016 17:11:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-5.0 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=notices, dozen, Hx-languages-length:3491 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; Thu, 22 Dec 2016 17:11:25 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 8E98C81F07; Thu, 22 Dec 2016 17:11:24 +0000 (UTC) Received: from localhost (ovpn-116-120.ams2.redhat.com [10.36.116.120]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uBMHBNIk009649; Thu, 22 Dec 2016 12:11:24 -0500 Date: Thu, 22 Dec 2016 17:11:23 +0000 From: Jonathan Wakely To: Ville Voutilainen Cc: libstdc++ , "gcc-patches@gcc.gnu.org" Subject: Re: [v3 PATCH] Implement 2801, Default-constructibility of unique_ptr. Message-ID: <20161222171123.GY895@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.1 (2016-10-04) On 20/12/16 22:52 +0200, Ville Voutilainen wrote: >diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h >index 56e6ec0..63dff37 100644 >--- a/libstdc++-v3/include/bits/unique_ptr.h >+++ b/libstdc++-v3/include/bits/unique_ptr.h >@@ -175,10 +175,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > // Constructors. > > /// Default constructor, creates a unique_ptr that owns nothing. >+ template + typename enable_if< >+ __and_<__not_>, >+ is_default_constructible<_Up>>::value, >+ bool>::type = false> Instead of repeating this condition half a dozen times, we could put it in the __uniq_ptr_impl class template and reuse it, as in the attached patch (and similarly for the unique_ptr specialization). What do you think? > constexpr unique_ptr() noexcept > : _M_t() >- { static_assert(!is_pointer::value, >- "constructed with null function pointer deleter"); } >+ { } The bodies of these constructors should be indented now that they're templates. >--- /dev/null >+++ b/libstdc++-v3/testsuite/20_util/unique_ptr/cons/default.cc >@@ -0,0 +1,40 @@ >+// { dg-do compile { target c++11 } } >+ >+// Copyright (C) 2011-2016 Free Software Foundation, Inc. Is this substantially copied from an existing file, or should it just be 2016? (Not that it really matters, as I don't think we should have copyright notices on tests like this at all, but that's something to worry about another time. diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h index 56e6ec0..f9ab9a6 100644 --- a/libstdc++-v3/include/bits/unique_ptr.h +++ b/libstdc++-v3/include/bits/unique_ptr.h @@ -130,6 +130,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; public: + using _DeleterConstraint = enable_if< + __and_<__not_, is_default_constructible<_Dp>>>::value>; + using pointer = typename _Ptr<_Tp, _Dp>::type; __uniq_ptr_impl() = default; @@ -152,6 +155,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template > class unique_ptr { + using _DeleterConstraint = __uniq_ptr_impl<_Tp, _Dp>::_DeleterConstraint; + __uniq_ptr_impl<_Tp, _Dp> _M_t; public: @@ -175,10 +180,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Constructors. /// Default constructor, creates a unique_ptr that owns nothing. - constexpr unique_ptr() noexcept - : _M_t() - { static_assert(!is_pointer::value, - "constructed with null function pointer deleter"); } + template + constexpr unique_ptr() noexcept + : _M_t() + { } /** Takes ownership of a pointer. * @@ -186,11 +191,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * The deleter will be value-initialized. */ - explicit - unique_ptr(pointer __p) noexcept - : _M_t(__p) - { static_assert(!is_pointer::value, - "constructed with null function pointer deleter"); } + template + explicit + unique_ptr(pointer __p) noexcept + : _M_t(__p) + { } /** Takes ownership of a pointer. * @@ -218,7 +223,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION "rvalue deleter bound to reference"); } /// Creates a unique_ptr that owns nothing. - constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } + template + constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } // Move constructors.