From da213403233a2c88a327d120bc767d16bc1698d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 5 Mar 2019 12:15:42 +0100 Subject: [PATCH] Fix #105 ("Fix gcc -Wdeprecated-copy") --- doc/container.qbk | 1 + include/boost/container/deque.hpp | 18 +++++++++++++++--- include/boost/container/detail/iterators.hpp | 20 ++++++++++++++++++-- include/boost/container/stable_vector.hpp | 15 +++++++++++++-- include/boost/container/vector.hpp | 13 ++++++++++++- 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/doc/container.qbk b/doc/container.qbk index e440402..bfd8d4e 100644 --- a/doc/container.qbk +++ b/doc/container.qbk @@ -1252,6 +1252,7 @@ use [*Boost.Container]? There are several reasons for that: * [@https://github.com/boostorg/container/issues/100 GitHub #100: ['"Compile error on Green Hills: container_detail::flat_tree has no member insert"]]. * [@https://github.com/boostorg/container/pull/103 GitHub #103: ['"Fix deallocating never-allocated storage in vector.merge()"]]. * [@https://github.com/boostorg/container/pull/104 GitHub #104: ['"Fix -Wmissing-noreturn clang warnings"]]. + * [@https://github.com/boostorg/container/pull/105 GitHub #105: ['"Fix gcc -Wdeprecated-copy"]]. [endsect] diff --git a/include/boost/container/deque.hpp b/include/boost/container/deque.hpp index eb120cd..1fa3e5d 100644 --- a/include/boost/container/deque.hpp +++ b/include/boost/container/deque.hpp @@ -127,7 +127,12 @@ class deque_iterator , value_type& >::type reference; - static std::size_t s_buffer_size() + class nat; + typedef typename dtl::if_c< IsConst + , deque_iterator + , nat>::type nonconst_iterator; + + BOOST_CONTAINER_FORCEINLINE static std::size_t s_buffer_size() { return deque_buf_size::value; } typedef Pointer val_alloc_ptr; @@ -154,7 +159,11 @@ class deque_iterator : m_cur(), m_first(), m_last(), m_node() //Value initialization to achieve "null iterators" (N3644) {} - deque_iterator(deque_iterator const& x) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE deque_iterator(const deque_iterator& x) BOOST_NOEXCEPT_OR_NOTHROW + : m_cur(x.get_cur()), m_first(x.get_first()), m_last(x.get_last()), m_node(x.get_node()) + {} + + BOOST_CONTAINER_FORCEINLINE deque_iterator(const nonconst_iterator& x) BOOST_NOEXCEPT_OR_NOTHROW : m_cur(x.get_cur()), m_first(x.get_first()), m_last(x.get_last()), m_node(x.get_node()) {} @@ -162,7 +171,10 @@ class deque_iterator : m_cur(cur), m_first(first), m_last(last), m_node(node) {} - deque_iterator unconst() const BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE deque_iterator& operator=(const deque_iterator& x) BOOST_NOEXCEPT_OR_NOTHROW + { m_cur = x.get_cur(); m_first = x.get_first(); m_last = x.get_last(); m_node = x.get_node(); return *this; } + + BOOST_CONTAINER_FORCEINLINE deque_iterator unconst() const BOOST_NOEXCEPT_OR_NOTHROW { return deque_iterator(this->get_cur(), this->get_first(), this->get_last(), this->get_node()); } diff --git a/include/boost/container/detail/iterators.hpp b/include/boost/container/detail/iterators.hpp index ad98b11..4ac7d49 100644 --- a/include/boost/container/detail/iterators.hpp +++ b/include/boost/container/detail/iterators.hpp @@ -799,7 +799,16 @@ struct iterator_types template class iterator_from_iiterator { - typedef typename iterator_types::type types_t; + typedef typename iterator_types::type types_t; + class nat + { + public: + IIterator get() const + { return IIterator(); } + }; + typedef typename dtl::if_c< IsConst + , iterator_from_iiterator + , nat>::type nonconst_iterator; public: typedef typename types_t::pointer pointer; @@ -816,10 +825,17 @@ class iterator_from_iiterator : m_iit(iit) {} - BOOST_CONTAINER_FORCEINLINE iterator_from_iiterator(iterator_from_iiterator const& other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE iterator_from_iiterator(const iterator_from_iiterator& other) BOOST_NOEXCEPT_OR_NOTHROW : m_iit(other.get()) {} + BOOST_CONTAINER_FORCEINLINE iterator_from_iiterator(const nonconst_iterator& other) BOOST_NOEXCEPT_OR_NOTHROW + : m_iit(other.get()) + {} + + BOOST_CONTAINER_FORCEINLINE iterator_from_iiterator& operator=(const iterator_from_iiterator& other) BOOST_NOEXCEPT_OR_NOTHROW + { m_iit = other.get(); return *this; } + BOOST_CONTAINER_FORCEINLINE iterator_from_iiterator& operator++() BOOST_NOEXCEPT_OR_NOTHROW { ++this->m_iit; return *this; } diff --git a/include/boost/container/stable_vector.hpp b/include/boost/container/stable_vector.hpp index d41132d..4449b1f 100644 --- a/include/boost/container/stable_vector.hpp +++ b/include/boost/container/stable_vector.hpp @@ -297,6 +297,10 @@ class stable_vector_iterator >::type pointer; typedef boost::intrusive::pointer_traits ptr_traits; typedef typename ptr_traits::reference reference; + class nat; + typedef typename dtl::if_c< IsConst + , stable_vector_iterator + , nat>::type nonconst_iterator; private: typedef typename non_const_ptr_traits::template @@ -324,11 +328,18 @@ class stable_vector_iterator : m_pn() //Value initialization to achieve "null iterators" (N3644) {} - stable_vector_iterator(stable_vector_iterator const& other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE stable_vector_iterator(const stable_vector_iterator& other) BOOST_NOEXCEPT_OR_NOTHROW : m_pn(other.node_pointer()) {} - node_ptr node_pointer() const BOOST_NOEXCEPT_OR_NOTHROW + stable_vector_iterator(const nonconst_iterator& other) BOOST_NOEXCEPT_OR_NOTHROW + : m_pn(other.node_pointer()) + {} + + BOOST_CONTAINER_FORCEINLINE stable_vector_iterator & operator=(const stable_vector_iterator& other) BOOST_NOEXCEPT_OR_NOTHROW + { m_pn = other.node_pointer(); return *this; } + + BOOST_CONTAINER_FORCEINLINE node_ptr node_pointer() const BOOST_NOEXCEPT_OR_NOTHROW { return node_ptr_traits::static_cast_from(m_pn); } public: diff --git a/include/boost/container/vector.hpp b/include/boost/container/vector.hpp index df42df5..214f560 100644 --- a/include/boost/container/vector.hpp +++ b/include/boost/container/vector.hpp @@ -96,6 +96,10 @@ class vec_iterator #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED private: Pointer m_ptr; + class nat; + typedef typename dtl::if_c< IsConst + , vec_iterator + , nat>::type nonconst_iterator; public: BOOST_CONTAINER_FORCEINLINE const Pointer &get_ptr() const BOOST_NOEXCEPT_OR_NOTHROW @@ -116,10 +120,17 @@ class vec_iterator : m_ptr() //Value initialization to achieve "null iterators" (N3644) {} - BOOST_CONTAINER_FORCEINLINE vec_iterator(vec_iterator const& other) BOOST_NOEXCEPT_OR_NOTHROW + BOOST_CONTAINER_FORCEINLINE vec_iterator(const vec_iterator& other) BOOST_NOEXCEPT_OR_NOTHROW : m_ptr(other.get_ptr()) {} + BOOST_CONTAINER_FORCEINLINE vec_iterator(const nonconst_iterator &other) BOOST_NOEXCEPT_OR_NOTHROW + : m_ptr(other.get_ptr()) + {} + + BOOST_CONTAINER_FORCEINLINE vec_iterator & operator=(const vec_iterator& other) BOOST_NOEXCEPT_OR_NOTHROW + { m_ptr = other.get_ptr(); return *this; } + //Pointer like operators BOOST_CONTAINER_FORCEINLINE reference operator*() const BOOST_NOEXCEPT_OR_NOTHROW { BOOST_ASSERT(!!m_ptr); return *m_ptr; }