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
This commit is contained in:
parent
fb037b5da5
commit
f2e2de5f85
@ -1,3 +1,14 @@
|
||||
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.
|
||||
|
@ -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 \
|
||||
|
@ -755,6 +755,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 \
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <bits/stl_function.h>
|
||||
#include <bits/allocator.h>
|
||||
#include <ext/alloc_traits.h>
|
||||
#include <ext/aligned_buffer.h>
|
||||
|
||||
namespace std _GLIBCXX_VISIBILITY(default)
|
||||
{
|
||||
@ -99,20 +100,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
|
||||
{
|
||||
_Fwd_list_node() = default;
|
||||
|
||||
typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type
|
||||
_M_storage;
|
||||
__gnu_cxx::__aligned_buffer<_Tp> _M_storage;
|
||||
|
||||
_Tp*
|
||||
_M_valptr() noexcept
|
||||
{
|
||||
return static_cast<_Tp*>(static_cast<void*>(&_M_storage));
|
||||
}
|
||||
{ return _M_storage._M_ptr(); }
|
||||
|
||||
const _Tp*
|
||||
_M_valptr() const noexcept
|
||||
{
|
||||
return static_cast<const _Tp*>(static_cast<const void*>(&_M_storage));
|
||||
}
|
||||
{ return _M_storage._M_ptr(); }
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -49,6 +49,8 @@
|
||||
#ifndef _SHARED_PTR_BASE_H
|
||||
#define _SHARED_PTR_BASE_H 1
|
||||
|
||||
#include <ext/aligned_buffer.h>
|
||||
|
||||
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<void*>(&_M_storage));
|
||||
_M_impl._M_ptr = _M_storage._M_ptr();
|
||||
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
||||
// 2070. allocate_shared should use allocator_traits<A>::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<void*>(&_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<sizeof(_Tp), alignment_of<_Tp>::value>::type
|
||||
_M_storage;
|
||||
__gnu_cxx::__aligned_buffer<_Tp> _M_storage;
|
||||
};
|
||||
|
||||
template<_Lock_policy _Lp>
|
||||
|
73
libstdc++-v3/include/ext/aligned_buffer.h
Normal file
73
libstdc++-v3/include/ext/aligned_buffer.h
Normal file
@ -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
|
||||
// <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 @@
|
||||
#include <bits/shared_ptr.h>
|
||||
#include <bits/uses_allocator.h>
|
||||
#include <bits/alloc_traits.h>
|
||||
#include <ext/aligned_buffer.h>
|
||||
|
||||
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<sizeof(_Res), __a_of::value> __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<void*>(&_M_storage); }
|
||||
};
|
||||
|
||||
/// A unique_ptr based on the instantiating type.
|
||||
|
@ -32,7 +32,7 @@ void test01()
|
||||
{
|
||||
X* px = 0;
|
||||
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" }
|
||||
// { dg-error "incomplete" "" { target *-*-* } 307 }
|
||||
|
Loading…
Reference in New Issue
Block a user