Commit f2e2de5f by Jonathan Wakely Committed by Jonathan Wakely

Makefile.am: Add ext/aligned_buffer.h

	* 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.

From-SVN: r197554
parent fb037b5d
2013-04-07 Jonathan Wakely <jwakely.gcc@gmail.com> 2013-04-07 Jonathan Wakely <jwakely.gcc@gmail.com>
* 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.
2013-04-07 Jonathan Wakely <jwakely.gcc@gmail.com>
* include/bits/forward_list.h: Only include required headers. * include/bits/forward_list.h: Only include required headers.
(forward_list::reference): Define directly, not using __alloc_traits. (forward_list::reference): Define directly, not using __alloc_traits.
(forward_list::const_reference): Likewise. (forward_list::const_reference): Likewise.
......
...@@ -495,6 +495,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext ...@@ -495,6 +495,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext
ext_builddir = ./ext ext_builddir = ./ext
ext_headers = \ ext_headers = \
${ext_srcdir}/algorithm \ ${ext_srcdir}/algorithm \
${ext_srcdir}/aligned_buffer.h \
${ext_srcdir}/alloc_traits.h \ ${ext_srcdir}/alloc_traits.h \
${ext_srcdir}/atomicity.h \ ${ext_srcdir}/atomicity.h \
${ext_srcdir}/array_allocator.h \ ${ext_srcdir}/array_allocator.h \
......
...@@ -755,6 +755,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext ...@@ -755,6 +755,7 @@ ext_srcdir = ${glibcxx_srcdir}/include/ext
ext_builddir = ./ext ext_builddir = ./ext
ext_headers = \ ext_headers = \
${ext_srcdir}/algorithm \ ${ext_srcdir}/algorithm \
${ext_srcdir}/aligned_buffer.h \
${ext_srcdir}/alloc_traits.h \ ${ext_srcdir}/alloc_traits.h \
${ext_srcdir}/atomicity.h \ ${ext_srcdir}/atomicity.h \
${ext_srcdir}/array_allocator.h \ ${ext_srcdir}/array_allocator.h \
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <bits/stl_function.h> #include <bits/stl_function.h>
#include <bits/allocator.h> #include <bits/allocator.h>
#include <ext/alloc_traits.h> #include <ext/alloc_traits.h>
#include <ext/aligned_buffer.h>
namespace std _GLIBCXX_VISIBILITY(default) namespace std _GLIBCXX_VISIBILITY(default)
{ {
...@@ -99,20 +100,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER ...@@ -99,20 +100,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ {
_Fwd_list_node() = default; _Fwd_list_node() = default;
typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
_M_storage;
_Tp* _Tp*
_M_valptr() noexcept _M_valptr() noexcept
{ { return _M_storage._M_ptr(); }
return static_cast<_Tp*>(static_cast<void*>(&_M_storage));
}
const _Tp* const _Tp*
_M_valptr() const noexcept _M_valptr() const noexcept
{ { return _M_storage._M_ptr(); }
return static_cast<const _Tp*>(static_cast<const void*>(&_M_storage));
}
}; };
/** /**
......
...@@ -49,6 +49,8 @@ ...@@ -49,6 +49,8 @@
#ifndef _SHARED_PTR_BASE_H #ifndef _SHARED_PTR_BASE_H
#define _SHARED_PTR_BASE_H 1 #define _SHARED_PTR_BASE_H 1
#include <ext/aligned_buffer.h>
namespace std _GLIBCXX_VISIBILITY(default) namespace std _GLIBCXX_VISIBILITY(default)
{ {
_GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
...@@ -393,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -393,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args) _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args)
: _M_impl(__a), _M_storage() : _M_impl(__a), _M_storage()
{ {
_M_impl._M_ptr = static_cast<_Tp*>(static_cast<void*>(&_M_storage)); _M_impl._M_ptr = _M_storage._M_ptr();
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2070. allocate_shared should use allocator_traits<A>::construct // 2070. allocate_shared should use allocator_traits<A>::construct
allocator_traits<_Alloc>::construct(__a, _M_impl._M_ptr, allocator_traits<_Alloc>::construct(__a, _M_impl._M_ptr,
...@@ -422,9 +424,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -422,9 +424,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_get_deleter(const std::type_info& __ti) noexcept _M_get_deleter(const std::type_info& __ti) noexcept
{ {
#ifdef __GXX_RTTI #ifdef __GXX_RTTI
return __ti == typeid(_Sp_make_shared_tag) return __ti == typeid(_Sp_make_shared_tag) ? _M_storage._M_addr() : 0;
? static_cast<void*>(&_M_storage)
: 0;
#else #else
return 0; return 0;
#endif #endif
...@@ -432,8 +432,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -432,8 +432,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
private: private:
_Impl _M_impl; _Impl _M_impl;
typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
_M_storage;
}; };
template<_Lock_policy _Lp> template<_Lock_policy _Lp>
......
// 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
// <http://www.gnu.org/licenses/>.
/** @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 <type_traits>
#else
# include <bits/c++0x_warning.h>
#endif
namespace __gnu_cxx
{
template<typename _Tp>
struct __aligned_buffer
: std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>
{
typename
std::aligned_storage<sizeof(_Tp), std::alignment_of<_Tp>::value>::type
_M_storage;
void*
_M_addr() noexcept
{
return static_cast<void*>(&_M_storage);
}
const void*
_M_addr() const noexcept
{
return static_cast<const void*>(&_M_storage);
}
_Tp*
_M_ptr() noexcept
{ return static_cast<_Tp*>(_M_addr()); }
const _Tp*
_M_ptr() const noexcept
{ return static_cast<const _Tp*>(_M_addr()); }
};
} // namespace
#endif /* _ALIGNED_BUFFER_H */
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include <bits/shared_ptr.h> #include <bits/shared_ptr.h>
#include <bits/uses_allocator.h> #include <bits/uses_allocator.h>
#include <bits/alloc_traits.h> #include <bits/alloc_traits.h>
#include <ext/aligned_buffer.h>
namespace std _GLIBCXX_VISIBILITY(default) namespace std _GLIBCXX_VISIBILITY(default)
{ {
...@@ -206,12 +207,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -206,12 +207,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct _Result : _Result_base struct _Result : _Result_base
{ {
private: private:
typedef alignment_of<_Res> __a_of; __gnu_cxx::__aligned_buffer<_Res> _M_storage;
typedef aligned_storage<sizeof(_Res), __a_of::value> __align_storage; bool _M_initialized;
typedef typename __align_storage::type __align_type;
__align_type _M_storage;
bool _M_initialized;
public: public:
typedef _Res result_type; typedef _Res result_type;
...@@ -226,26 +223,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -226,26 +223,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
// Return lvalue, future will add const or rvalue-reference // Return lvalue, future will add const or rvalue-reference
_Res& _Res&
_M_value() noexcept { return *static_cast<_Res*>(_M_addr()); } _M_value() noexcept { return *_M_storage._M_ptr(); }
void void
_M_set(const _Res& __res) _M_set(const _Res& __res)
{ {
::new (_M_addr()) _Res(__res); ::new (_M_storage._M_addr()) _Res(__res);
_M_initialized = true; _M_initialized = true;
} }
void void
_M_set(_Res&& __res) _M_set(_Res&& __res)
{ {
::new (_M_addr()) _Res(std::move(__res)); ::new (_M_storage._M_addr()) _Res(std::move(__res));
_M_initialized = true; _M_initialized = true;
} }
private: private:
void _M_destroy() { delete this; } void _M_destroy() { delete this; }
void* _M_addr() noexcept { return static_cast<void*>(&_M_storage); }
}; };
/// A unique_ptr based on the instantiating type. /// A unique_ptr based on the instantiating type.
......
...@@ -32,7 +32,7 @@ void test01() ...@@ -32,7 +32,7 @@ void test01()
{ {
X* px = 0; X* px = 0;
std::shared_ptr<X> p1(px); // { dg-error "here" } std::shared_ptr<X> p1(px); // { dg-error "here" }
// { dg-error "incomplete" "" { target *-*-* } 771 } // { dg-error "incomplete" "" { target *-*-* } 770 }
std::shared_ptr<X> p9(ap()); // { dg-error "here" } std::shared_ptr<X> p9(ap()); // { dg-error "here" }
// { dg-error "incomplete" "" { target *-*-* } 307 } // { dg-error "incomplete" "" { target *-*-* } 307 }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment