From 8274b281879404286fb36ab4dee3e69442a837cd Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 27 Jun 2014 20:03:26 +0000 Subject: [PATCH] 2014-06-27 Paolo Carlini * Revert r212046 and r212054. From-SVN: r212085 --- libstdc++-v3/ChangeLog | 27 -- .../forward_list/debug/move_assign_neg.cc | 2 +- .../map/debug/move_assign_neg.cc | 3 +- .../multimap/debug/move_assign_neg.cc | 3 +- .../multiset/debug/move_assign_neg.cc | 2 +- .../set/debug/move_assign_neg.cc | 2 +- .../unordered_map/debug/move_assign_neg.cc | 3 +- .../debug/move_assign_neg.cc | 3 +- .../debug/move_assign_neg.cc | 2 +- .../unordered_set/debug/move_assign_neg.cc | 2 +- .../vector/debug/move_assign_neg.cc | 2 +- .../testsuite/util/testsuite_allocator.h | 341 ++++++++---------- 12 files changed, 167 insertions(+), 225 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4fcc7ff5efa..ba61134f7bd 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,30 +1,3 @@ -2014-06-26 François Dumont - - * testsuite/util/testsuite_allocator.h - (tracker_allocator_counter::allocate): Remove new invocation, only - collect information. - (tracker_allocator_counter::deallocate): Remove delete invocation, only - collect information. - (check_inconsistent_alloc_value_type): New. - (tracker_allocator): Transform as a facade for any allocator type. - (uneq_allocator): Likewise. - (propagating_allocator): Likewise. - * testsuite/23_containers/forward_list/debug/move_assign_neg.cc: Use an - explicitly non propagating allocator. - * testsuite/23_containers/map/debug/move_assign_neg.cc: Likewise. - * testsuite/23_containers/multimap/debug/move_assign_neg.cc: likewise. - * testsuite/23_containers/multiset/debug/move_assign_neg.cc: Likewise. - * testsuite/23_containers/set/debug/move_assign_neg.cc: Likewise. - * testsuite/23_containers/unordered_map/debug/move_assign_neg.cc: - Likewise. - * testsuite/23_containers/unordered_multimap/debug/move_assign_neg.cc: - Likewise. - * testsuite/23_containers/unordered_multiset/debug/move_assign_neg.cc: - Likewise. - * testsuite/23_containers/unordered_set/debug/move_assign_neg.cc: - Likewise. - * testsuite/23_containers/vector/debug/move_assign_neg.cc: Likewise. - 2014-06-26 Jonathan Wakely * include/bits/shared_ptr_base.h (__shared_ptr::_Deleter): Fix diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/forward_list/debug/move_assign_neg.cc index 934afbedd6b..91e459fd3c3 100644 --- a/libstdc++-v3/testsuite/23_containers/forward_list/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/forward_list/debug/move_assign_neg.cc @@ -25,7 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator alloc_type; + typedef __gnu_test::uneq_allocator alloc_type; typedef __gnu_debug::forward_list test_type; test_type v1(alloc_type(1)); diff --git a/libstdc++-v3/testsuite/23_containers/map/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/map/debug/move_assign_neg.cc index 3f2a7ca532b..0d63fe944bf 100644 --- a/libstdc++-v3/testsuite/23_containers/map/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/map/debug/move_assign_neg.cc @@ -25,8 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator, - false> alloc_type; + typedef __gnu_test::uneq_allocator > alloc_type; typedef __gnu_debug::map, alloc_type> test_type; test_type v1(alloc_type(1)); diff --git a/libstdc++-v3/testsuite/23_containers/multimap/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/multimap/debug/move_assign_neg.cc index da2950fe458..e514a28dbed 100644 --- a/libstdc++-v3/testsuite/23_containers/multimap/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/multimap/debug/move_assign_neg.cc @@ -25,8 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator, - false> alloc_type; + typedef __gnu_test::uneq_allocator > alloc_type; typedef __gnu_debug::multimap, alloc_type> test_type; test_type v1(alloc_type(1)); diff --git a/libstdc++-v3/testsuite/23_containers/multiset/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/multiset/debug/move_assign_neg.cc index 6f5f5b430cc..af879d94dad 100644 --- a/libstdc++-v3/testsuite/23_containers/multiset/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/multiset/debug/move_assign_neg.cc @@ -25,7 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator alloc_type; + typedef __gnu_test::uneq_allocator alloc_type; typedef __gnu_debug::multiset, alloc_type> test_type; test_type v1(alloc_type(1)); diff --git a/libstdc++-v3/testsuite/23_containers/set/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/set/debug/move_assign_neg.cc index b491a03276d..b7f51efd393 100644 --- a/libstdc++-v3/testsuite/23_containers/set/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/set/debug/move_assign_neg.cc @@ -25,7 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator alloc_type; + typedef __gnu_test::uneq_allocator alloc_type; typedef __gnu_debug::set, alloc_type> test_type; test_type v1(alloc_type(1)); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/move_assign_neg.cc index 3670f73b0d3..ef5db1165f3 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_map/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/debug/move_assign_neg.cc @@ -25,8 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator, - false> alloc_type; + typedef __gnu_test::uneq_allocator > alloc_type; typedef __gnu_debug::unordered_map, std::equal_to, alloc_type> test_type; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/move_assign_neg.cc index 7a8fa77c4d8..b6de1eef581 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/debug/move_assign_neg.cc @@ -25,8 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator, - false> alloc_type; + typedef __gnu_test::uneq_allocator> alloc_type; typedef __gnu_debug::unordered_multimap, std::equal_to, alloc_type> test_type; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/move_assign_neg.cc index 9fe72e1f254..52a8df2a9f2 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multiset/debug/move_assign_neg.cc @@ -25,7 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator alloc_type; + typedef __gnu_test::uneq_allocator alloc_type; typedef __gnu_debug::unordered_multiset, std::equal_to, alloc_type> test_type; diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/move_assign_neg.cc index b1b71e118ff..9d2a8abc425 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/debug/move_assign_neg.cc @@ -25,7 +25,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator alloc_type; + typedef __gnu_test::uneq_allocator alloc_type; typedef __gnu_debug::unordered_set, std::equal_to, alloc_type> test_type; diff --git a/libstdc++-v3/testsuite/23_containers/vector/debug/move_assign_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/debug/move_assign_neg.cc index 3de0723195e..eb2233b35fe 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/debug/move_assign_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/debug/move_assign_neg.cc @@ -27,7 +27,7 @@ void test01() { bool test __attribute__((unused)) = true; - typedef __gnu_test::propagating_allocator alloc_type; + typedef __gnu_test::uneq_allocator alloc_type; typedef __gnu_debug::vector test_type; test_type v1(alloc_type(1)); diff --git a/libstdc++-v3/testsuite/util/testsuite_allocator.h b/libstdc++-v3/testsuite/util/testsuite_allocator.h index 68a12ee8705..822a025f4fa 100644 --- a/libstdc++-v3/testsuite/util/testsuite_allocator.h +++ b/libstdc++-v3/testsuite/util/testsuite_allocator.h @@ -29,7 +29,6 @@ #include #include #include -#include #include namespace __gnu_test @@ -39,19 +38,26 @@ namespace __gnu_test public: typedef std::size_t size_type; - static void + static void* allocate(size_type blocksize) - { allocationCount_ += blocksize; } + { + void* p = ::operator new(blocksize); + allocationCount_ += blocksize; + return p; + } static void - construct() { ++constructCount_; } + construct() { constructCount_++; } static void - destroy() { ++destructCount_; } + destroy() { destructCount_++; } static void - deallocate(size_type blocksize) - { deallocationCount_ += blocksize; } + deallocate(void* p, size_type blocksize) + { + ::operator delete(p); + deallocationCount_ += blocksize; + } static size_type get_allocation_count() { return allocationCount_; } @@ -81,142 +87,103 @@ namespace __gnu_test static int destructCount_; }; - // Helper to detect inconsistency between type used to instantiate an - // allocator and the underlying allocator value_type. - template - struct check_consistent_alloc_value_type; + // A simple basic allocator that just forwards to the + // tracker_allocator_counter to fulfill memory requests. This class + // is templated on the target object type, but tracker isn't. + template + class tracker_allocator + { + private: + typedef tracker_allocator_counter counter_type; - template - struct check_consistent_alloc_value_type - { typedef T value_type; }; - - // An allocator facade that intercepts allocate/deallocate/construct/destroy - // calls and track them through the tracker_allocator_counter class. This - // class is templated on the target object type, but tracker isn't. - template > - class tracker_allocator : public Alloc - { - private: - typedef tracker_allocator_counter counter_type; - - typedef __gnu_cxx::__alloc_traits AllocTraits; - - public: - typedef typename - check_consistent_alloc_value_type::value_type value_type; - typedef typename AllocTraits::pointer pointer; - typedef typename AllocTraits::size_type size_type; + public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; - template - struct rebind - { - typedef tracker_allocator::other> other; - }; + template struct rebind { typedef tracker_allocator other; }; -#if __cplusplus >= 201103L - tracker_allocator() = default; - tracker_allocator(const tracker_allocator&) = default; - tracker_allocator(tracker_allocator&&) = default; + pointer + address(reference value) const _GLIBCXX_NOEXCEPT + { return std::__addressof(value); } - // Perfect forwarding constructor. - template - tracker_allocator(_Args&&... __args) - : Alloc(std::forward<_Args>(__args)...) - { } -#else - tracker_allocator() + const_pointer + address(const_reference value) const _GLIBCXX_NOEXCEPT + { return std::__addressof(value); } + + tracker_allocator() _GLIBCXX_USE_NOEXCEPT + { } + + tracker_allocator(const tracker_allocator&) _GLIBCXX_USE_NOEXCEPT + { } + + template + tracker_allocator(const tracker_allocator&) _GLIBCXX_USE_NOEXCEPT { } - tracker_allocator(const tracker_allocator&) - { } + ~tracker_allocator() _GLIBCXX_USE_NOEXCEPT + { } - ~tracker_allocator() - { } -#endif + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return size_type(-1) / sizeof(T); } - template - tracker_allocator(const tracker_allocator::other>& alloc) - _GLIBCXX_USE_NOEXCEPT - : Alloc(alloc) - { } - - pointer - allocate(size_type n, const void* = 0) - { - pointer p = AllocTraits::allocate(*this, n); - counter_type::allocate(n * sizeof(T)); - return p; - } + pointer + allocate(size_type n, const void* = 0) + { return static_cast(counter_type::allocate(n * sizeof(T))); } #if __cplusplus >= 201103L - template - void - construct(U* p, Args&&... args) - { - AllocTraits::construct(*this, p, std::forward(args)...); - counter_type::construct(); - } - - template - void - destroy(U* p) - { - AllocTraits::destroy(*this, p); - counter_type::destroy(); - } -#else + template void - construct(pointer p, const T& value) + construct(U* p, Args&&... args) { - AllocTraits::construct(*this, p, value); + ::new((void *)p) U(std::forward(args)...); counter_type::construct(); } + template void - destroy(pointer p) + destroy(U* p) { - AllocTraits::destroy(*this, p); + p->~U(); counter_type::destroy(); } -#endif - - void - deallocate(pointer p, size_type num) - { - counter_type::deallocate(num * sizeof(T)); - AllocTraits::deallocate(*this, p, num); - } - - // Implement swap for underlying allocators that might need it. - friend inline void - swap(tracker_allocator& a, tracker_allocator& b) - { - using std::swap; - - Alloc& aa = a; - Alloc& ab = b; - swap(aa, ab); - } - }; - - template - bool - operator==(const tracker_allocator& lhs, - const tracker_allocator& rhs) throw() +#else + void + construct(pointer p, const T& value) { - const Alloc1& alloc1 = lhs; - const Alloc2& alloc2 = rhs; - return lhs == rhs; + ::new ((void *)p) T(value); + counter_type::construct(); } - template + void + destroy(pointer p) + { + p->~T(); + counter_type::destroy(); + } +#endif + + void + deallocate(pointer p, size_type num) + { counter_type::deallocate(p, num * sizeof(T)); } + }; + + template bool - operator!=(const tracker_allocator& lhs, - const tracker_allocator& rhs) throw() - { return !(lhs == rhs); } + operator==(const tracker_allocator&, + const tracker_allocator&) throw() + { return true; } + + template + bool + operator!=(const tracker_allocator&, + const tracker_allocator&) throw() + { return false; } bool check_construct_destroy(const char* tag, int expected_c, int expected_d); @@ -226,7 +193,7 @@ namespace __gnu_test check_deallocate_null() { // Let's not core here... - Alloc a; + Alloc a; a.deallocate(0, 1); a.deallocate(0, 10); return true; @@ -252,6 +219,7 @@ namespace __gnu_test throw; } + // A simple allocator which can be constructed endowed of a given // "personality" (an integer), queried in operator== to simulate the // behavior of realworld "unequal" allocators (i.e., not exploiting @@ -259,7 +227,7 @@ namespace __gnu_test // filled at allocation time with (pointer, personality) pairs, is // then consulted to enforce the requirements in Table 32 about // deallocation vs allocator equality. Note that this allocator is - // swappable, not copy assignable, consistently with Option 3 of DR 431 + // swappable, not assignable, consistently with Option 3 of DR 431 // (see N1599). struct uneq_allocator_base { @@ -276,33 +244,26 @@ namespace __gnu_test } }; - template > + template class uneq_allocator - : private uneq_allocator_base, - public Alloc + : private uneq_allocator_base { - typedef __gnu_cxx::__alloc_traits AllocTraits; - - Alloc& base() { return *this; } - const Alloc& base() const { return *this; } - void swap_base(Alloc& b) { swap(b, this->base()); } - public: - typedef typename check_consistent_alloc_value_type::value_type - value_type; - typedef typename AllocTraits::size_type size_type; - typedef typename AllocTraits::pointer pointer; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + typedef Tp* pointer; + typedef const Tp* const_pointer; + typedef Tp& reference; + typedef const Tp& const_reference; + typedef Tp value_type; #if __cplusplus >= 201103L - typedef std::true_type propagate_on_container_swap; + typedef std::true_type propagate_on_container_swap; #endif template - struct rebind - { - typedef uneq_allocator::other> other; - }; + struct rebind + { typedef uneq_allocator other; }; uneq_allocator() _GLIBCXX_USE_NOEXCEPT : personality(0) { } @@ -311,9 +272,7 @@ namespace __gnu_test : personality(person) { } template - uneq_allocator(const uneq_allocator::other>& b) - _GLIBCXX_USE_NOEXCEPT + uneq_allocator(const uneq_allocator& b) _GLIBCXX_USE_NOEXCEPT : personality(b.get_personality()) { } ~uneq_allocator() _GLIBCXX_USE_NOEXCEPT @@ -322,9 +281,20 @@ namespace __gnu_test int get_personality() const { return personality; } pointer - allocate(size_type n, const void* hint = 0) + address(reference x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(x); } + + const_pointer + address(const_reference x) const _GLIBCXX_NOEXCEPT + { return std::__addressof(x); } + + pointer + allocate(size_type n, const void* = 0) { - pointer p = AllocTraits::allocate(*this, n); + if (__builtin_expect(n > this->max_size(), false)) + std::__throw_bad_alloc(); + + pointer p = static_cast(::operator new(n * sizeof(Tp))); try { get_map().insert(map_type::value_type(reinterpret_cast(p), @@ -332,14 +302,14 @@ namespace __gnu_test } catch(...) { - AllocTraits::deallocate(*this, p, n); + ::operator delete(p); __throw_exception_again; } return p; } void - deallocate(pointer p, size_type n) + deallocate(pointer p, size_type) { bool test __attribute__((unused)) = true; @@ -353,18 +323,34 @@ namespace __gnu_test VERIFY( it->second == personality ); get_map().erase(it); - AllocTraits::deallocate(*this, p, n); + ::operator delete(p); } + size_type + max_size() const _GLIBCXX_USE_NOEXCEPT + { return size_type(-1) / sizeof(Tp); } + #if __cplusplus >= 201103L + template + void + construct(U* p, Args&&... args) + { ::new((void *)p) U(std::forward(args)...); } + + template + void + destroy(U* p) { p->~U(); } + // Not copy assignable... uneq_allocator& operator=(const uneq_allocator&) = delete; - - // ... but still moveable if base allocator is. - uneq_allocator& - operator=(uneq_allocator&&) = default; #else + void + construct(pointer p, const Tp& val) + { ::new((void *)p) Tp(val); } + + void + destroy(pointer p) { p->~Tp(); } + private: // Not assignable... uneq_allocator& @@ -372,39 +358,31 @@ namespace __gnu_test #endif private: + // ... yet swappable! friend inline void swap(uneq_allocator& a, uneq_allocator& b) - { - std::swap(a.personality, b.personality); - a.swap_base(b); - } + { std::swap(a.personality, b.personality); } + + template + friend inline bool + operator==(const uneq_allocator& a, const uneq_allocator& b) + { return a.personality == b.personality; } template - friend inline bool - operator==(const uneq_allocator& a, - const uneq_allocator::other>& b) - { return a.personality == b.personality; } - - template - friend inline bool - operator!=(const uneq_allocator& a, - const uneq_allocator::other>& b) - { return !(a == b); } + friend inline bool + operator!=(const uneq_allocator& a, const uneq_allocator& b) + { return !(a == b); } int personality; }; #if __cplusplus >= 201103L // An uneq_allocator which can be used to test allocator propagation. - template> - class propagating_allocator : public uneq_allocator + template + class propagating_allocator : public uneq_allocator { - typedef __gnu_cxx::__alloc_traits AllocTraits; - - typedef uneq_allocator base_alloc; + typedef uneq_allocator base_alloc; base_alloc& base() { return *this; } const base_alloc& base() const { return *this; } void swap_base(base_alloc& b) { swap(b, this->base()); } @@ -415,20 +393,15 @@ namespace __gnu_test // default allocator_traits::rebind_alloc would select // uneq_allocator::rebind so we must define rebind here template - struct rebind - { - typedef propagating_allocator::other> other; - }; + struct rebind { typedef propagating_allocator other; }; propagating_allocator(int i) noexcept : base_alloc(i) { } template - propagating_allocator(const propagating_allocator::other>& a) - noexcept + propagating_allocator(const propagating_allocator& a) + noexcept : base_alloc(a) { } @@ -445,8 +418,8 @@ namespace __gnu_test } template - propagating_allocator& - operator=(const propagating_allocator& a) noexcept + propagating_allocator& + operator=(const propagating_allocator& a) noexcept { static_assert(P2, "assigning propagating_allocator"); propagating_allocator(a).swap_base(*this);