mirror of git://gcc.gnu.org/git/gcc.git
stl_tree.h (_Rb_tree_impl()): Restore _Node_allocator default init.
2017-06-12 François Dumont <fdumont@gcc.gnu.org> * include/bits/stl_tree.h (_Rb_tree_impl()): Restore _Node_allocator default init. * testsuite/util/testsuite_allocator.h (__gnu_test::default_init_allocator<>) New. * testsuite/23_containers/set/allocator/default_init.cc: New. * testsuite/23_containers/map/allocator/default_init.cc: New. From-SVN: r249136
This commit is contained in:
parent
6d1ea02a6c
commit
07cfc2d75d
|
|
@ -1,3 +1,12 @@
|
|||
2017-06-12 François Dumont <fdumont@gcc.gnu.org>
|
||||
|
||||
* include/bits/stl_tree.h (_Rb_tree_impl()): Restore _Node_allocator
|
||||
default init.
|
||||
* testsuite/util/testsuite_allocator.h
|
||||
(__gnu_test::default_init_allocator<>) New.
|
||||
* testsuite/23_containers/set/allocator/default_init.cc: New.
|
||||
* testsuite/23_containers/map/allocator/default_init.cc: New.
|
||||
|
||||
2017-06-12 Jonathan Wakely <jwakely@redhat.com>
|
||||
|
||||
PR libstdc++/55917
|
||||
|
|
|
|||
|
|
@ -572,11 +572,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
|
||||
_Node_allocator&
|
||||
_M_get_Node_allocator() _GLIBCXX_NOEXCEPT
|
||||
{ return *static_cast<_Node_allocator*>(&this->_M_impl); }
|
||||
{ return this->_M_impl; }
|
||||
|
||||
const _Node_allocator&
|
||||
_M_get_Node_allocator() const _GLIBCXX_NOEXCEPT
|
||||
{ return *static_cast<const _Node_allocator*>(&this->_M_impl); }
|
||||
{ return this->_M_impl; }
|
||||
|
||||
allocator_type
|
||||
get_allocator() const _GLIBCXX_NOEXCEPT
|
||||
|
|
@ -685,13 +685,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
{
|
||||
typedef _Rb_tree_key_compare<_Key_compare> _Base_key_compare;
|
||||
|
||||
#if __cplusplus < 201103L
|
||||
_Rb_tree_impl()
|
||||
_GLIBCXX_NOEXCEPT_IF(
|
||||
is_nothrow_default_constructible<_Node_allocator>::value
|
||||
&& is_nothrow_default_constructible<_Base_key_compare>::value )
|
||||
: _Node_allocator()
|
||||
{ }
|
||||
#else
|
||||
_Rb_tree_impl() = default;
|
||||
_Rb_tree_impl(_Rb_tree_impl&&) = default;
|
||||
#endif
|
||||
|
||||
_Rb_tree_impl(const _Rb_tree_impl& __x)
|
||||
: _Node_allocator(_Alloc_traits::_S_select_on_copy(__x))
|
||||
|
|
@ -703,6 +702,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
|||
: _Node_allocator(__a), _Base_key_compare(__comp)
|
||||
{ }
|
||||
#else
|
||||
_Rb_tree_impl(_Rb_tree_impl&&) = default;
|
||||
|
||||
_Rb_tree_impl(const _Key_compare& __comp, _Node_allocator&& __a)
|
||||
: _Node_allocator(std::move(__a)), _Base_key_compare(__comp)
|
||||
{ }
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright (C) 2017 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.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-do run { target c++11 } }
|
||||
// { dg-options "-O0" }
|
||||
// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
|
||||
|
||||
#include <map>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_allocator.h>
|
||||
|
||||
#include <ext/aligned_buffer.h>
|
||||
|
||||
using T = int;
|
||||
|
||||
using __gnu_test::default_init_allocator;
|
||||
|
||||
void test01()
|
||||
{
|
||||
typedef default_init_allocator<std::pair<const T, T>> alloc_type;
|
||||
typedef std::map<T, T, std::less<T>, alloc_type> test_type;
|
||||
|
||||
__gnu_cxx::__aligned_buffer<test_type> buf;
|
||||
__builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
|
||||
|
||||
test_type *tmp = ::new(buf._M_addr()) test_type;
|
||||
|
||||
VERIFY( tmp->get_allocator().state == 0 );
|
||||
|
||||
tmp->~test_type();
|
||||
}
|
||||
|
||||
void test02()
|
||||
{
|
||||
typedef default_init_allocator<std::pair<const T, T>> alloc_type;
|
||||
typedef std::map<T, T, std::less<T>, alloc_type> test_type;
|
||||
|
||||
__gnu_cxx::__aligned_buffer<test_type> buf;
|
||||
__builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
|
||||
|
||||
test_type *tmp = ::new(buf._M_addr()) test_type();
|
||||
|
||||
VERIFY( tmp->get_allocator().state == 0 );
|
||||
|
||||
tmp->~test_type();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
// Copyright (C) 2017 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.
|
||||
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with this library; see the file COPYING3. If not see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
// { dg-do run { target c++11 } }
|
||||
// { dg-options "-O0" }
|
||||
// { dg-xfail-run-if "PR c++/65816" { *-*-* } }
|
||||
|
||||
#include <set>
|
||||
#include <testsuite_hooks.h>
|
||||
#include <testsuite_allocator.h>
|
||||
|
||||
#include <ext/aligned_buffer.h>
|
||||
|
||||
using T = int;
|
||||
|
||||
using __gnu_test::default_init_allocator;
|
||||
|
||||
void test01()
|
||||
{
|
||||
typedef default_init_allocator<T> alloc_type;
|
||||
typedef std::set<T, std::less<T>, alloc_type> test_type;
|
||||
|
||||
__gnu_cxx::__aligned_buffer<test_type> buf;
|
||||
__builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
|
||||
|
||||
test_type *tmp = ::new(buf._M_addr()) test_type;
|
||||
|
||||
VERIFY( tmp->get_allocator().state == 0 );
|
||||
|
||||
tmp->~test_type();
|
||||
}
|
||||
|
||||
void test02()
|
||||
{
|
||||
typedef default_init_allocator<T> alloc_type;
|
||||
typedef std::set<T, std::less<T>, alloc_type> test_type;
|
||||
|
||||
__gnu_cxx::__aligned_buffer<test_type> buf;
|
||||
__builtin_memset(buf._M_addr(), ~0, sizeof(test_type));
|
||||
|
||||
test_type *tmp = ::new(buf._M_addr()) test_type();
|
||||
|
||||
VERIFY( tmp->get_allocator().state == 0 );
|
||||
|
||||
tmp->~test_type();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -508,6 +508,38 @@ namespace __gnu_test
|
|||
bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
|
||||
{ return false; }
|
||||
|
||||
template<typename T>
|
||||
struct default_init_allocator
|
||||
{
|
||||
using value_type = T;
|
||||
|
||||
default_init_allocator() = default;
|
||||
|
||||
template<typename U>
|
||||
default_init_allocator(const default_init_allocator<U>& a)
|
||||
: state(a.state)
|
||||
{ }
|
||||
|
||||
T*
|
||||
allocate(std::size_t n)
|
||||
{ return std::allocator<T>().allocate(n); }
|
||||
|
||||
void
|
||||
deallocate(T* p, std::size_t n)
|
||||
{ std::allocator<T>().deallocate(p, n); }
|
||||
|
||||
int state;
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
bool operator==(const default_init_allocator<T>& t,
|
||||
const default_init_allocator<U>& u)
|
||||
{ return t.state == u.state; }
|
||||
|
||||
template<typename T, typename U>
|
||||
bool operator!=(const default_init_allocator<T>& t,
|
||||
const default_init_allocator<U>& u)
|
||||
{ return !(t == u); }
|
||||
#endif
|
||||
|
||||
template<typename Tp>
|
||||
|
|
|
|||
Loading…
Reference in New Issue