aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrançois Dumont <fdumont@gcc.gnu.org>2017-06-12 20:38:16 +0000
committerFrançois Dumont <fdumont@gcc.gnu.org>2017-06-12 20:38:16 +0000
commit07cfc2d75d85c5fc961bdd8434673f0a5f40587d (patch)
treeffe9b9b9b57625a8e8ca439834e062bbdc18e050
parent6d1ea02a6c3423a000c0d894b2ff673757042398 (diff)
downloadgcc-07cfc2d75d85c5fc961bdd8434673f0a5f40587d.zip
gcc-07cfc2d75d85c5fc961bdd8434673f0a5f40587d.tar.gz
gcc-07cfc2d75d85c5fc961bdd8434673f0a5f40587d.tar.bz2
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
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/bits/stl_tree.h15
-rw-r--r--libstdc++-v3/testsuite/23_containers/map/allocator/default_init.cc67
-rw-r--r--libstdc++-v3/testsuite/23_containers/set/allocator/default_init.cc67
-rw-r--r--libstdc++-v3/testsuite/util/testsuite_allocator.h32
5 files changed, 183 insertions, 7 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 9e0a590..5ee9e68 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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
diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h
index 3f133b0..c2417f1 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -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)
{ }
diff --git a/libstdc++-v3/testsuite/23_containers/map/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/map/allocator/default_init.cc
new file mode 100644
index 0000000..1ef13d9
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/map/allocator/default_init.cc
@@ -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;
+}
diff --git a/libstdc++-v3/testsuite/23_containers/set/allocator/default_init.cc b/libstdc++-v3/testsuite/23_containers/set/allocator/default_init.cc
new file mode 100644
index 0000000..4e14e18
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/set/allocator/default_init.cc
@@ -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;
+}
diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h
index 56c2708..233ea0b 100644
--- a/libstdc++-v3/testsuite/util/testsuite_allocator.h
+++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h
@@ -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>