From 86d4d21250d451be72b7c39b2abfd00cc0241024 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 11 Jul 2014 08:40:07 +0100 Subject: [PATCH 1/4] Make value_base a member of pointer nodes. --- include/boost/unordered/detail/equivalent.hpp | 7 ++++++- include/boost/unordered/detail/unique.hpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/boost/unordered/detail/equivalent.hpp b/include/boost/unordered/detail/equivalent.hpp index d5538d73..58478f99 100644 --- a/include/boost/unordered/detail/equivalent.hpp +++ b/include/boost/unordered/detail/equivalent.hpp @@ -52,15 +52,16 @@ namespace boost { namespace unordered { namespace detail { template struct grouped_ptr_node : - boost::unordered::detail::value_base, boost::unordered::detail::ptr_bucket { + typedef T value_type; typedef boost::unordered::detail::ptr_bucket bucket_base; typedef grouped_ptr_node* node_pointer; typedef ptr_bucket* link_pointer; node_pointer group_prev_; std::size_t hash_; + boost::unordered::detail::value_base value_base_; grouped_ptr_node() : bucket_base(), @@ -73,6 +74,10 @@ namespace boost { namespace unordered { namespace detail { group_prev_ = self; } + void* address() { return value_base_.address(); } + value_type& value() { return value_base_.value(); } + value_type* value_ptr() { return value_base_.value_ptr(); } + private: grouped_ptr_node& operator=(grouped_ptr_node const&); }; diff --git a/include/boost/unordered/detail/unique.hpp b/include/boost/unordered/detail/unique.hpp index 5fd5a46d..0f0f5951 100644 --- a/include/boost/unordered/detail/unique.hpp +++ b/include/boost/unordered/detail/unique.hpp @@ -49,14 +49,15 @@ namespace boost { namespace unordered { namespace detail { template struct ptr_node : - boost::unordered::detail::value_base, boost::unordered::detail::ptr_bucket { + typedef T value_type; typedef boost::unordered::detail::ptr_bucket bucket_base; typedef ptr_node* node_pointer; typedef ptr_bucket* link_pointer; std::size_t hash_; + boost::unordered::detail::value_base value_base_; ptr_node() : bucket_base(), @@ -67,6 +68,10 @@ namespace boost { namespace unordered { namespace detail { { } + void* address() { return value_base_.address(); } + value_type& value() { return value_base_.value(); } + value_type* value_ptr() { return value_base_.value_ptr(); } + private: ptr_node& operator=(ptr_node const&); }; From 2216c987a0035b69590d8b259cf4bed65ec0b076 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Fri, 11 Jul 2014 09:13:47 +0100 Subject: [PATCH 2/4] Fixed direct use of allocator. --- include/boost/unordered/detail/unique.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/boost/unordered/detail/unique.hpp b/include/boost/unordered/detail/unique.hpp index 0f0f5951..f76ca5a6 100644 --- a/include/boost/unordered/detail/unique.hpp +++ b/include/boost/unordered/detail/unique.hpp @@ -28,7 +28,9 @@ namespace boost { namespace unordered { namespace detail { boost::unordered::detail::value_base { typedef typename ::boost::unordered::detail::rebind_wrap< - A, unique_node >::type::pointer node_pointer; + A, unique_node >::type allocator; + typedef typename ::boost::unordered::detail:: + allocator_traits::pointer node_pointer; typedef node_pointer link_pointer; link_pointer next_; From 2f5d98a0cd8464d429768180ed034f6e08400c6d Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 12 Jul 2014 19:12:46 +0100 Subject: [PATCH 3/4] Don't use allocator to construct/destroy anything other than elements. As specified in 23.2.1.3. --- doc/changes.qbk | 3 +++ include/boost/unordered/detail/allocate.hpp | 11 +++++++---- include/boost/unordered/detail/buckets.hpp | 7 +++---- include/boost/unordered/detail/table.hpp | 7 +++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/doc/changes.qbk b/doc/changes.qbk index 30b465e3..d93a63ea 100644 --- a/doc/changes.qbk +++ b/doc/changes.qbk @@ -239,5 +239,8 @@ C++11 support has resulted in some breaking changes: * Avoid some warnings ([ticket 8851], [ticket 8874]). * Avoid exposing some detail functions via. ADL on the iterators. +* Follow the standard by only using the allocators' construct and destroy + methods to construct and destroy stored elements. Don't use them for internal + data like pointers. [endsect] diff --git a/include/boost/unordered/detail/allocate.hpp b/include/boost/unordered/detail/allocate.hpp index bca63e6a..4c20b168 100644 --- a/include/boost/unordered/detail/allocate.hpp +++ b/include/boost/unordered/detail/allocate.hpp @@ -1081,8 +1081,10 @@ namespace boost { namespace unordered { namespace detail { ~array_constructor() { if (ptr_) { - for(pointer p = ptr_; p != constructed_; ++p) - traits::destroy(alloc_, boost::addressof(*p)); + for(pointer p = ptr_; p != constructed_; ++p) { + boost::unordered::detail::func::destroy( + boost::addressof(*p)); + } traits::deallocate(alloc_, ptr_, length_); } @@ -1095,8 +1097,9 @@ namespace boost { namespace unordered { namespace detail { length_ = l; ptr_ = traits::allocate(alloc_, length_); pointer end = ptr_ + static_cast(length_); - for(constructed_ = ptr_; constructed_ != end; ++constructed_) - traits::construct(alloc_, boost::addressof(*constructed_), v); + for(constructed_ = ptr_; constructed_ != end; ++constructed_) { + new ((void*) boost::addressof(*constructed_)) V(v); + } } pointer get() const diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index 6ad3808b..fd038b7b 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -402,7 +402,7 @@ namespace boost { namespace unordered { namespace detail { } if (node_constructed_) { - node_allocator_traits::destroy(alloc_, + boost::unordered::detail::func::destroy( boost::addressof(*node_)); } @@ -419,8 +419,7 @@ namespace boost { namespace unordered { namespace detail { node_ = node_allocator_traits::allocate(alloc_, 1); - node_allocator_traits::construct(alloc_, - boost::addressof(*node_), node()); + new ((void*) boost::addressof(*node_)) node(); node_->init(node_); node_constructed_ = true; } @@ -548,7 +547,7 @@ namespace boost { namespace unordered { namespace detail { boost::unordered::detail::func::destroy_value_impl(this->alloc_, p->value_ptr()); - node_allocator_traits::destroy(this->alloc_, boost::addressof(*p)); + boost::unordered::detail::func::destroy(boost::addressof(*p)); node_allocator_traits::deallocate(this->alloc_, p, 1); } } diff --git a/include/boost/unordered/detail/table.hpp b/include/boost/unordered/detail/table.hpp index 65fb780c..7b4cc0ec 100644 --- a/include/boost/unordered/detail/table.hpp +++ b/include/boost/unordered/detail/table.hpp @@ -523,8 +523,7 @@ namespace boost { namespace unordered { namespace detail { boost::unordered::detail::func::destroy_value_impl(node_alloc(), n->value_ptr()); - node_allocator_traits::destroy(node_alloc(), - boost::addressof(*n)); + boost::unordered::detail::func::destroy(boost::addressof(*n)); node_allocator_traits::deallocate(node_alloc(), n, 1); --size_; } @@ -551,7 +550,7 @@ namespace boost { namespace unordered { namespace detail { if (bucket::extra_node) { node_pointer n = static_cast( get_bucket(bucket_count_)->next_); - node_allocator_traits::destroy(node_alloc(), + boost::unordered::detail::func::destroy( boost::addressof(*n)); node_allocator_traits::deallocate(node_alloc(), n, 1); } @@ -588,7 +587,7 @@ namespace boost { namespace unordered { namespace detail { bucket_pointer end = get_bucket(bucket_count_ + 1); for(bucket_pointer it = buckets_; it != end; ++it) { - bucket_allocator_traits::destroy(bucket_alloc(), + boost::unordered::detail::func::destroy( boost::addressof(*it)); } From 15cb6d7d1b2f42d1f8530e1045f15c0bfa2d447d Mon Sep 17 00:00:00 2001 From: Daniel James Date: Mon, 14 Jul 2014 21:49:58 +0100 Subject: [PATCH 4/4] Tweak warning flags in tests. --- test/exception/Jamfile.v2 | 9 ++------- test/unordered/Jamfile.v2 | 4 +--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/test/exception/Jamfile.v2 b/test/exception/Jamfile.v2 index aa280ffb..c5d6f403 100644 --- a/test/exception/Jamfile.v2 +++ b/test/exception/Jamfile.v2 @@ -12,13 +12,8 @@ project unordered-test/exception-tests : requirements all intel:on - gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter" - darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter" - #gcc:_GLIBCXX_DEBUG - #darwin:_GLIBCXX_DEBUG - #msvc:on - #gcc:on - #darwin:on + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow -Wno-long-long" + darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" ; test-suite unordered-exception diff --git a/test/unordered/Jamfile.v2 b/test/unordered/Jamfile.v2 index 52e09bf0..460ef135 100644 --- a/test/unordered/Jamfile.v2 +++ b/test/unordered/Jamfile.v2 @@ -11,10 +11,8 @@ project unordered-test/unordered intel:on # Would be nice to define -Wundef, but I'm getting warnings from # Boost.Preprocessor on trunk. - gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wno-long-long -Wfloat-equal -Wshadow" + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow -Wno-long-long" darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" - #gcc:_GLIBCXX_DEBUG - #darwin:_GLIBCXX_DEBUG ; test-suite unordered