From 7764e05444bdda2c6fadf3afaab1b50f8bd3cd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Mon, 12 Oct 2015 18:51:08 +0200 Subject: [PATCH] Changes to support GCC 3.4 --- include/boost/container/deque.hpp | 11 ++++------ include/boost/container/detail/mutex.hpp | 4 ++-- include/boost/container/detail/tree.hpp | 7 +++--- include/boost/container/flat_map.hpp | 7 ++++-- include/boost/container/map.hpp | 6 +++++- include/boost/container/stable_vector.hpp | 26 +++++++++++------------ test/expand_bwd_test_allocator.hpp | 2 +- test/resource_adaptor_test.cpp | 4 ++++ test/scoped_allocator_usage_test.cpp | 8 ++++--- test/vector_test.cpp | 3 +++ 10 files changed, 45 insertions(+), 33 deletions(-) diff --git a/include/boost/container/deque.hpp b/include/boost/container/deque.hpp index 14ba6da..f53f34a 100644 --- a/include/boost/container/deque.hpp +++ b/include/boost/container/deque.hpp @@ -1672,9 +1672,8 @@ class deque : protected deque_base //! if(pos is near the beginning). iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW { - BOOST_ASSERT(first <= last); - BOOST_ASSERT(first == last || this->priv_in_range(first)); - BOOST_ASSERT(first == last || this->priv_in_range_or_end(last)); + BOOST_ASSERT(first == last || + (first < last && this->priv_in_range(first) && this->priv_in_range_or_end(last))); if (first == this->members_.m_start && last == this->members_.m_finish) { this->clear(); return this->members_.m_finish; @@ -2052,8 +2051,7 @@ class deque : protected deque_base } template - typename iterator_enable_if_tag::type - priv_range_initialize(InIt first, InIt last) + void priv_range_initialize(InIt first, InIt last, typename iterator_enable_if_tag::type* =0) { this->priv_initialize_map(0); BOOST_TRY { @@ -2068,8 +2066,7 @@ class deque : protected deque_base } template - typename iterator_disable_if_tag::type - priv_range_initialize(FwdIt first, FwdIt last) + void priv_range_initialize(FwdIt first, FwdIt last, typename iterator_disable_if_tag::type* =0) { size_type n = 0; n = boost::container::iterator_distance(first, last); diff --git a/include/boost/container/detail/mutex.hpp b/include/boost/container/detail/mutex.hpp index f8efa7f..82e8810 100644 --- a/include/boost/container/detail/mutex.hpp +++ b/include/boost/container/detail/mutex.hpp @@ -107,7 +107,7 @@ #elif (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) /* Custom spin locks for older gcc on x86 */ - static FORCEINLINE int boost_container_x86_cas_lock(int *sl) { + static inline int boost_container_x86_cas_lock(int *sl) { int ret; int val = 1; int cmp = 0; @@ -118,7 +118,7 @@ return ret; } - static FORCEINLINE void boost_container_x86_clear_lock(int* sl) { + static inline void boost_container_x86_clear_lock(int* sl) { assert(*sl != 0); int prev = 0; int ret; diff --git a/include/boost/container/detail/tree.hpp b/include/boost/container/detail/tree.hpp index 575565c..956e460 100644 --- a/include/boost/container/detail/tree.hpp +++ b/include/boost/container/detail/tree.hpp @@ -408,13 +408,12 @@ struct key_node_compare }; template - typename enable_if_c::value, const typename KeyValueCompare::value_type &>::type - key_forward(const T &node) const + const typename KeyValueCompare::value_type & + key_forward(const T &node, typename enable_if_c::value>::type* =0) const { return node.get_data(); } template - typename enable_if_c::value, const T &>::type - key_forward(const T &key) const + const T &key_forward(const T &key, typename enable_if_c::value>::type* =0) const { return key; } template diff --git a/include/boost/container/flat_map.hpp b/include/boost/container/flat_map.hpp index ef0e1cb..da9d87c 100644 --- a/include/boost/container/flat_map.hpp +++ b/include/boost/container/flat_map.hpp @@ -593,9 +593,12 @@ class flat_map //! //! Complexity: Logarithmic. mapped_type &operator[](key_type &&k) ; - + #elif defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN) + //in compilers like GCC 3.4, we can't catch temporaries + mapped_type& operator[](const key_type &k) { return this->priv_subscript(k); } + mapped_type& operator[](BOOST_RV_REF(key_type) k) { return this->priv_subscript(::boost::move(k)); } #else - BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript) + BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript) #endif //! @copydoc ::boost::container::flat_set::nth(size_type) diff --git a/include/boost/container/map.hpp b/include/boost/container/map.hpp index 4dc6096..8173181 100644 --- a/include/boost/container/map.hpp +++ b/include/boost/container/map.hpp @@ -481,8 +481,12 @@ class map //! //! Complexity: Logarithmic. mapped_type& operator[](key_type &&k); + #elif defined(BOOST_MOVE_HELPERS_RETURN_SFINAE_BROKEN) + //in compilers like GCC 3.4, we can't catch temporaries + mapped_type& operator[](const key_type &k) { return this->priv_subscript(k); } + mapped_type& operator[](BOOST_RV_REF(key_type) k) { return this->priv_subscript(::boost::move(k)); } #else - BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript) + BOOST_MOVE_CONVERSION_AWARE_CATCH( operator[] , key_type, mapped_type&, this->priv_subscript) #endif //! Returns: A reference to the element whose key is equivalent to x. diff --git a/include/boost/container/stable_vector.hpp b/include/boost/container/stable_vector.hpp index 4a4a47b..a332dbc 100644 --- a/include/boost/container/stable_vector.hpp +++ b/include/boost/container/stable_vector.hpp @@ -1531,16 +1531,17 @@ class stable_vector //! //! Complexity: Linear to distance [first, last). template - #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) - typename container_detail::disable_if_or - < iterator - , container_detail::is_convertible - , container_detail::is_not_input_iterator - >::type - #else - iterator - #endif - insert(const_iterator p, InputIterator first, InputIterator last) + iterator insert(const_iterator p, InputIterator first, InputIterator last + #if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED) + //Put this as argument instead of the return type as old GCC's like 3.4 + //detect this and the next disable_if_or as overloads + , typename container_detail::disable_if_or + < void + , container_detail::is_convertible + , container_detail::is_not_input_iterator + >::type* = 0 + #endif + ) { BOOST_ASSERT(this->priv_in_range_or_end(p)); STABLE_VECTOR_CHECK_INVARIANT; @@ -1630,9 +1631,8 @@ class stable_vector //! plus linear to the elements between p and the last element. iterator erase(const_iterator first, const_iterator last) BOOST_NOEXCEPT_OR_NOTHROW { - BOOST_ASSERT(first <= last); - BOOST_ASSERT(first == last || this->priv_in_range(first)); - BOOST_ASSERT(first == last || this->priv_in_range_or_end(last)); + BOOST_ASSERT(first == last || + (first < last && this->priv_in_range(first) && this->priv_in_range_or_end(last))); STABLE_VECTOR_CHECK_INVARIANT; const const_iterator cbeg(this->cbegin()); const size_type d1 = static_cast(first - cbeg), diff --git a/test/expand_bwd_test_allocator.hpp b/test/expand_bwd_test_allocator.hpp index 2e16093..925858a 100644 --- a/test/expand_bwd_test_allocator.hpp +++ b/test/expand_bwd_test_allocator.hpp @@ -79,7 +79,7 @@ class expand_bwd_test_allocator { typedef expand_bwd_test_allocator other; }; //!Constructor from the segment manager. Never throws - expand_bwd_test_allocator(T *buffer, size_type sz, difference_type offset) + expand_bwd_test_allocator(T *buffer = 0, size_type sz = 0, difference_type offset = 0) : mp_buffer(buffer), m_size(sz) , m_offset(offset), m_allocations(0){ } diff --git a/test/resource_adaptor_test.cpp b/test/resource_adaptor_test.cpp index df72f85..412d471 100644 --- a/test/resource_adaptor_test.cpp +++ b/test/resource_adaptor_test.cpp @@ -92,6 +92,10 @@ struct stateful struct rebind { typedef stateful other; }; + stateful() + : m_u(0u) + {} + char *allocate(std::size_t n) { allocate_size = n; return allocate_return; } diff --git a/test/scoped_allocator_usage_test.cpp b/test/scoped_allocator_usage_test.cpp index 2e90205..d12e4fa 100644 --- a/test/scoped_allocator_usage_test.cpp +++ b/test/scoped_allocator_usage_test.cpp @@ -31,7 +31,7 @@ class SimpleAllocator public: typedef Ty value_type; - explicit SimpleAllocator(int value) + explicit SimpleAllocator(int value = 0) : m_state(value) {} @@ -356,7 +356,8 @@ bool one_level_allocator_propagation_test() typedef typename ContainerWrapper::allocator_type allocator_type; typedef typename ContainerWrapper::value_type value_type; { - ContainerWrapper c(allocator_type(SimpleAllocator(5))); + allocator_type al(SimpleAllocator(5)); + ContainerWrapper c(al); c.clear(); iterator it = c.emplace(c.cbegin(), 42); @@ -365,7 +366,8 @@ bool one_level_allocator_propagation_test() return false; } { - ContainerWrapper c2(allocator_type(SimpleAllocator(4))); + allocator_type al(SimpleAllocator(4)); + ContainerWrapper c2(al); ContainerWrapper c(::boost::move(c2), allocator_type(SimpleAllocator(5))); c.clear(); diff --git a/test/vector_test.cpp b/test/vector_test.cpp index 332941a..c746440 100644 --- a/test/vector_test.cpp +++ b/test/vector_test.cpp @@ -95,6 +95,9 @@ int test_expand_bwd() class recursive_vector { public: + recursive_vector & operator=(const recursive_vector &x) + { this->vector_ = x.vector_; return *this; } + int id_; vector vector_; vector::iterator it_;