+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
_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
{
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))
: _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)
{ }
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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;
+}
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>