std::vector default default and move constructors

Jonathan Wakely jwakely@redhat.com
Tue Jun 26 13:46:00 GMT 2018


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.






More information about the Gcc-patches mailing list