From patchwork Thu Oct 20 11:37:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 78491 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp732387qge; Thu, 20 Oct 2016 04:37:43 -0700 (PDT) X-Received: by 10.36.185.69 with SMTP id k5mr7344327iti.21.1476963462971; Thu, 20 Oct 2016 04:37:42 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id zs7si2663595pac.301.2016.10.20.04.37.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Oct 2016 04:37:42 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439111-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-439111-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439111-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=yOuXUZ5xTI5oJiQWUOr4nWiTN4ebam 5UiaYsX9ZaF1PxWSeq4XmLDJsxksBwAJz2+z8rbSyvLuSRwee9QtJy/ETmC/xwwA vEiEKTl+YIszTRoAFqGcRjydpVuoi+CO+MXMmwvbiVXW+YBjj7MBO4P9if5hsh7P eCcsmiBWRfGyw= 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=Tu18vEv3lV7SUjKY5oskDjasOUo=; b=kpXi 8N/PeRcthcdN/+obSltKicfBBxmorAPyPguqTiJiWP802O3ZKBSCMwqUW7dBojzr C+KRHEzHz8pIszmAT6aOzg9dMJSfvWsH9HhYpmdYAkl25q9TNHLPorPnOOSS+E2a xJLed697ajwKzQSQzSZx51k0aG2dNr6smUilN2w= Received: (qmail 53550 invoked by alias); 20 Oct 2016 11:37:26 -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 53526 invoked by uid 89); 20 Oct 2016 11:37:25 -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=154, 7, 1547, 977, 97, 7 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, 20 Oct 2016 11:37:24 +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 CE6B0C0567A3; Thu, 20 Oct 2016 11:37:22 +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 u9KBbMt6013581; Thu, 20 Oct 2016 07:37:22 -0400 Date: Thu, 20 Oct 2016 12:37:21 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] PR78052 Define std::allocator::{construct, destroy} Message-ID: <20161020113721.GG2922@redhat.com> References: <20161020101256.GA14544@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161020101256.GA14544@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) On 20/10/16 11:12 +0100, Jonathan Wakely wrote: >This let's std::allocator be used in situations like: > >std::allocate_shared(std::allocator(), 1); > >where a "proto-allocator" is required. The other members such as >allocate() and max_size() don't make sense for void, but construct and >destroy don't depend on value_type. > > PR libstdc++/78052 > * include/bits/allocator.h (allocator::construct) > (allocator::destroy): Define. > * testsuite/20_util/allocator/void.cc: New test. > >Tested x86_64-linux, committed to trunk. Also applying to gcc-5 and >gcc-6 branches, because this used to work before I put in the >allocator_traits> partial specialization. Some whitespace cleanup in the allocator files. Committed to trunk. commit 5612ef6e6ed6ffec81b8499f8a72753ae017ca92 Author: Jonathan Wakely Date: Thu Oct 20 12:02:06 2016 +0100 Tweak whitespace in std::allocator files * include/bits/allocator.h: Remove trailing whitespace, tab-indent. * include/ext/new_allocator.h: Likewise. diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h index 9fb5842..327e250 100644 --- a/libstdc++-v3/include/bits/allocator.h +++ b/libstdc++-v3/include/bits/allocator.h @@ -75,8 +75,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef void value_type; template - struct rebind - { typedef allocator<_Tp1> other; }; + struct rebind + { typedef allocator<_Tp1> other; }; #if __cplusplus >= 201103L // _GLIBCXX_RESOLVE_LIB_DEFECTS @@ -86,13 +86,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef true_type is_always_equal; template - void - construct(_Up* __p, _Args&&... __args) + void + construct(_Up* __p, _Args&&... __args) { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } template - void - destroy(_Up* __p) { __p->~_Up(); } + void + destroy(_Up* __p) { __p->~_Up(); } #endif }; @@ -117,8 +117,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef _Tp value_type; template - struct rebind - { typedef allocator<_Tp1> other; }; + struct rebind + { typedef allocator<_Tp1> other; }; #if __cplusplus >= 201103L // _GLIBCXX_RESOLVE_LIB_DEFECTS @@ -134,7 +134,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : __allocator_base<_Tp>(__a) { } template - allocator(const allocator<_Tp1>&) throw() { } + allocator(const allocator<_Tp1>&) throw() { } ~allocator() throw() { } diff --git a/libstdc++-v3/include/ext/new_allocator.h b/libstdc++-v3/include/ext/new_allocator.h index 2ff4780..7633029 100644 --- a/libstdc++-v3/include/ext/new_allocator.h +++ b/libstdc++-v3/include/ext/new_allocator.h @@ -48,7 +48,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @brief An allocator that uses global new, as per [20.4]. * @ingroup allocators * - * This is precisely the allocator defined in the C++ Standard. + * This is precisely the allocator defined in the C++ Standard. * - all allocation calls operator new * - all deallocation calls operator delete * @@ -67,8 +67,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef _Tp value_type; template - struct rebind - { typedef new_allocator<_Tp1> other; }; + struct rebind + { typedef new_allocator<_Tp1> other; }; #if __cplusplus >= 201103L // _GLIBCXX_RESOLVE_LIB_DEFECTS @@ -81,7 +81,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION new_allocator(const new_allocator&) _GLIBCXX_USE_NOEXCEPT { } template - new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { } + new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { } ~new_allocator() _GLIBCXX_USE_NOEXCEPT { } @@ -97,7 +97,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // about what the return value is when __n == 0. pointer allocate(size_type __n, const void* = 0) - { + { if (__n > this->max_size()) std::__throw_bad_alloc(); @@ -131,21 +131,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus >= 201103L template - void - construct(_Up* __p, _Args&&... __args) + void + construct(_Up* __p, _Args&&... __args) { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } template - void - destroy(_Up* __p) { __p->~_Up(); } + void + destroy(_Up* __p) { __p->~_Up(); } #else // _GLIBCXX_RESOLVE_LIB_DEFECTS // 402. wrong new expression in [some_] allocator::construct - void - construct(pointer __p, const _Tp& __val) + void + construct(pointer __p, const _Tp& __val) { ::new((void *)__p) _Tp(__val); } - void + void destroy(pointer __p) { __p->~_Tp(); } #endif }; @@ -154,7 +154,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline bool operator==(const new_allocator<_Tp>&, const new_allocator<_Tp>&) { return true; } - + template inline bool operator!=(const new_allocator<_Tp>&, const new_allocator<_Tp>&)