This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::vector default default and move constructors
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: François Dumont <frs dot dumont at gmail dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 26 Jun 2018 14:46:19 +0100
- Subject: Re: std::vector default default and move constructors
- References: <2b48d135-7b0f-f8ec-73f5-15932c2a8581@gmail.com> <d4e95591-30ec-b366-d79e-df8416d44ef1@gmail.com> <1653b9da-8fee-d534-0185-3a63a69d5ca1@gmail.com> <2b6cd500-135a-4d23-9cfd-e064efabdfa7@gmail.com> <alpine.DEB.2.21.1801110748090.5897@stedding.saclay.inria.fr> <48c96890-91fa-ac4e-9df8-452139987955@gmail.com> <20180115122914.GJ24454@redhat.com> <fa620c68-ad59-ff66-40b9-e014d655cebe@gmail.com> <20180116002054.GL24454@redhat.com> <9a050bcd-ce7a-7342-e31e-bbb9b4ca72dc@gmail.com>
On 02/06/18 14:00 +0200, François Dumont wrote:
Hi
Here is this patch again, I consider all your remarks and also
made some changes considering feedback on rbtree patch.
+ _Vector_impl(_Tp_alloc_type const& __a) _GLIBCXX_NOEXCEPT
+ : _Tp_alloc_type(__a)
+ { }
+
+#if __cplusplus >= 201103L
+ // Not defaulted to avoid noexcept qualification dependency on the
+ // _Tp_alloc_type move constructor one.
Could you please rephrase this comment as:
// Not defaulted, to enforce noexcept(true) even when
// !is_nothrow_move_constructible<_Tp_alloc_type>.
I prefer this wording, because most allocators don't have a move
constructor at all (just a copy constructor) so talking about its move
constructor is misleading.
+ _Vector_impl(_Vector_impl&& __x) noexcept
+ : _Tp_alloc_type(std::move(__x)), _Vector_impl_data(std::move(__x))
+ { }
+
+ _Vector_impl(_Tp_alloc_type&& __a) noexcept
+ : _Tp_alloc_type(std::move(__a))
+ { }
+
+ _Vector_impl(_Tp_alloc_type&& __a, _Vector_impl&& __rv) noexcept
+ : _Tp_alloc_type(std::move(__a)), _Vector_impl_data(std::move(__rv))
+ { }
+#endif
#if _GLIBCXX_SANITIZE_STD_ALLOCATOR && _GLIBCXX_SANITIZE_VECTOR
template<typename = _Tp_alloc_type>
@@ -235,38 +259,42 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_Tp_alloc_type&
_M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
- { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); }
+ { return this->_M_impl; }
const _Tp_alloc_type&
_M_get_Tp_allocator() const _GLIBCXX_NOEXCEPT
- { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); }
+ { return this->_M_impl; }
allocator_type
get_allocator() const _GLIBCXX_NOEXCEPT
{ return allocator_type(_M_get_Tp_allocator()); }
- _Vector_base()
- : _M_impl() { }
+#if __cplusplus >= 201103L
+ _Vector_base() = default;
+#else
+ _Vector_base() { }
+#endif
_Vector_base(const allocator_type& __a) _GLIBCXX_NOEXCEPT
: _M_impl(__a) { }
Please add "// Kept for ABI compatibility" before this #if:
+#if !_GLIBCXX_INLINE_VERSION
_Vector_base(size_t __n)
: _M_impl()
{ _M_create_storage(__n); }
+#endif
_Vector_base(size_t __n, const allocator_type& __a)
: _M_impl(__a)
{ _M_create_storage(__n); }
#if __cplusplus >= 201103L
+ _Vector_base(_Vector_base&&) = default;
+
And here too:
+# if !_GLIBCXX_INLINE_VERSION
_Vector_base(_Tp_alloc_type&& __a) noexcept
: _M_impl(std::move(__a)) { }
OK for trunk with those three comment changes.
Thanks for your patience waiting for the review.