From patchwork Sun Apr 7 16:48:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 234506 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 9DCF42C00A6 for ; Mon, 8 Apr 2013 02:48:48 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=vfh802nPjOzr1//n9Vj2+m+EWPPd6Xe0nxekstPuL8KZlO syqnIFbrXQSIn6fBrCFQGhORU/GoWXxQs6BiCz9yzHhnMNelV3G21lp4rXp9kmIi YNMgn2FXdUfMUkLJ04J+gKNv9ChwkENwJNwwMQ5xMb6Ae7EZK8pWDZucWaZhM= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=JkNTSuMTd1h+cjsCEFYgoeZR87o=; b=G0CR85kt9VORLVldkSwz ZCSAG4EWKJ6kNIScwbcOXdQQO9AG4w36Ye0HOEWKbWnuBbYWzeR/SVY6KjH4Jv5p mqrFDeMR9B0Jd4GwmXEbqfTZ/Q9uMxd1UaJYx1gp64MqQ394lx0TbpfFliAfl5iL pQa4/RdNM6sNldXxHvqSTlU= Received: (qmail 15315 invoked by alias); 7 Apr 2013 16:48:39 -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 15297 invoked by uid 89); 7 Apr 2013 16:48:39 -0000 X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, FILL_THIS_FORM_SHORT, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_CX autolearn=no version=3.3.1 X-Spam-User: qpsmtpd, 2 recipients Received: from mail-lb0-f177.google.com (HELO mail-lb0-f177.google.com) (209.85.217.177) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Sun, 07 Apr 2013 16:48:32 +0000 Received: by mail-lb0-f177.google.com with SMTP id r10so5051431lbi.36 for ; Sun, 07 Apr 2013 09:48:30 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.112.8.164 with SMTP id s4mr9692843lba.106.1365353310134; Sun, 07 Apr 2013 09:48:30 -0700 (PDT) Received: by 10.112.29.102 with HTTP; Sun, 7 Apr 2013 09:48:30 -0700 (PDT) Date: Sun, 7 Apr 2013 17:48:30 +0100 Message-ID: Subject: [v3] Define __gnu_cxx::__aligned_buffer From: Jonathan Wakely To: "libstdc++" , gcc-patches X-Virus-Found: No This patch adds a new utility type that wraps a member of type std::aligned_storage and provides some convenient accessors, to replace repeated uses of the same code in the library. The new type should also be used in the other node-based containers when they gain C++11 allocator support. * include/Makefile.am: Add ext/aligned_buffer.h * include/Makefile.in: Regenerate. * include/ext/aligned_buffer.h: New. * include/std/future (_Result): Use __aligned_buffer. * include/bits/forward_list.h (_Fwd_list_node): Likewise. * include/bits/shared_ptr_base.h (_Sp_counted_ptr_inplace): Likewise. * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error line number. Tested x86_64-linux, committed to trunk. commit 69bb2ce62fd89844ffef503483631ead23a4aafa Author: Jonathan Wakely Date: Sun Apr 7 17:42:47 2013 +0100 * include/Makefile.am: Add ext/aligned_buffer.h * include/Makefile.in: Regenerate. * include/ext/aligned_buffer.h: New. * include/std/future (_Result): Use __aligned_buffer. * include/bits/forward_list.h (_Fwd_list_node): Likewise. * include/bits/shared_ptr_base.h (_Sp_counted_ptr_inplace): Likewise. * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust dg-error line number. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 6bd3b43..b0ea41d 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -495,6 +495,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext ext_builddir = ./ext ext_headers = \ ${ext_srcdir}/algorithm \ + ${ext_srcdir}/aligned_buffer.h \ ${ext_srcdir}/alloc_traits.h \ ${ext_srcdir}/atomicity.h \ ${ext_srcdir}/array_allocator.h \ diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index 8270c4e..e7c4bdd 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -39,6 +39,7 @@ #include #include #include +#include namespace std _GLIBCXX_VISIBILITY(default) { @@ -99,20 +100,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { _Fwd_list_node() = default; - typename aligned_storage::value>::type - _M_storage; + __gnu_cxx::__aligned_buffer<_Tp> _M_storage; _Tp* _M_valptr() noexcept - { - return static_cast<_Tp*>(static_cast(&_M_storage)); - } + { return _M_storage._M_ptr(); } const _Tp* _M_valptr() const noexcept - { - return static_cast(static_cast(&_M_storage)); - } + { return _M_storage._M_ptr(); } }; /** diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h b/libstdc++-v3/include/bits/shared_ptr_base.h index c5df1fb..f463645 100644 --- a/libstdc++-v3/include/bits/shared_ptr_base.h +++ b/libstdc++-v3/include/bits/shared_ptr_base.h @@ -49,6 +49,8 @@ #ifndef _SHARED_PTR_BASE_H #define _SHARED_PTR_BASE_H 1 +#include + namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION @@ -393,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args) : _M_impl(__a), _M_storage() { - _M_impl._M_ptr = static_cast<_Tp*>(static_cast(&_M_storage)); + _M_impl._M_ptr = _M_storage._M_ptr(); // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2070. allocate_shared should use allocator_traits::construct allocator_traits<_Alloc>::construct(__a, _M_impl._M_ptr, @@ -422,9 +424,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_get_deleter(const std::type_info& __ti) noexcept { #ifdef __GXX_RTTI - return __ti == typeid(_Sp_make_shared_tag) - ? static_cast(&_M_storage) - : 0; + return __ti == typeid(_Sp_make_shared_tag) ? _M_storage._M_addr() : 0; #else return 0; #endif @@ -432,8 +432,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION private: _Impl _M_impl; - typename aligned_storage::value>::type - _M_storage; + __gnu_cxx::__aligned_buffer<_Tp> _M_storage; }; template<_Lock_policy _Lp> diff --git a/libstdc++-v3/include/ext/aligned_buffer.h b/libstdc++-v3/include/ext/aligned_buffer.h new file mode 100644 index 0000000..ffed88c --- /dev/null +++ b/libstdc++-v3/include/ext/aligned_buffer.h @@ -0,0 +1,73 @@ +// Aligned memory buffer -*- C++ -*- + +// Copyright (C) 2013 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file ext/aligned_buffer.h + * This file is a GNU extension to the Standard C++ Library. + */ + +#ifndef _ALIGNED_BUFFER_H +#define _ALIGNED_BUFFER_H 1 + +#pragma GCC system_header + +#if __cplusplus >= 201103L +# include +#else +# include +#endif + +namespace __gnu_cxx +{ + template + struct __aligned_buffer + : std::aligned_storage::value> + { + typename + std::aligned_storage::value>::type + _M_storage; + + void* + _M_addr() noexcept + { + return static_cast(&_M_storage); + } + + const void* + _M_addr() const noexcept + { + return static_cast(&_M_storage); + } + + _Tp* + _M_ptr() noexcept + { return static_cast<_Tp*>(_M_addr()); } + + const _Tp* + _M_ptr() const noexcept + { return static_cast(_M_addr()); } + }; + +} // namespace + +#endif /* _ALIGNED_BUFFER_H */ diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index 30100fe..a86a7ca 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -46,6 +46,7 @@ #include #include #include +#include namespace std _GLIBCXX_VISIBILITY(default) { @@ -206,12 +207,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct _Result : _Result_base { private: - typedef alignment_of<_Res> __a_of; - typedef aligned_storage __align_storage; - typedef typename __align_storage::type __align_type; - - __align_type _M_storage; - bool _M_initialized; + __gnu_cxx::__aligned_buffer<_Res> _M_storage; + bool _M_initialized; public: typedef _Res result_type; @@ -226,26 +223,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Return lvalue, future will add const or rvalue-reference _Res& - _M_value() noexcept { return *static_cast<_Res*>(_M_addr()); } + _M_value() noexcept { return *_M_storage._M_ptr(); } void _M_set(const _Res& __res) { - ::new (_M_addr()) _Res(__res); + ::new (_M_storage._M_addr()) _Res(__res); _M_initialized = true; } void _M_set(_Res&& __res) { - ::new (_M_addr()) _Res(std::move(__res)); + ::new (_M_storage._M_addr()) _Res(std::move(__res)); _M_initialized = true; } private: void _M_destroy() { delete this; } - - void* _M_addr() noexcept { return static_cast(&_M_storage); } }; /// A unique_ptr based on the instantiating type. diff --git a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc index 6fa34a9..3a5f053 100644 --- a/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc +++ b/libstdc++-v3/testsuite/20_util/shared_ptr/cons/43820_neg.cc @@ -32,7 +32,7 @@ void test01() { X* px = 0; std::shared_ptr p1(px); // { dg-error "here" } - // { dg-error "incomplete" "" { target *-*-* } 771 } + // { dg-error "incomplete" "" { target *-*-* } 770 } std::shared_ptr p9(ap()); // { dg-error "here" } // { dg-error "incomplete" "" { target *-*-* } 307 }