std::vector default default and move constructors
François Dumont
frs.dumont@gmail.com
Wed Jun 27 20:27:00 GMT 2018
Commited attached patch.
It fixes the missing noexcept qualification on a __gnu_debug::vector<>
constructor.
2018-06-27 François Dumont <fdumont@gcc.gnu.org>
   * include/bits/stl_vector.h
   (struct _Vector_base<>::_Vector_impl_data): New.
   (struct _Vector_base<>::_Vector_impl): Inherit from latter.
   (_Vector_base<>::_Vector_impl::_M_swap_data): Move...
   (_Vector_base<>::_Vector_impl_data::_M_swap_data): ...here.
   (_Vector_base<>::_Vector_impl()): Add noexcept qualification.
   (_Vector_base<>::_Vector_impl(_Vector_impl&&)): New.
   (_Vector_base<>::_Vector_impl(_Tp_alloc_type&&, _Vector_impl&&)): New.
   (_Vector_base(const allocator_type&, _Vector_base&&)): New, use latter.
   (_Vector_base()): Default.
   (_Vector_base(_Vector_base&&)): Default.
   (_Vector_base(size_t)) [_GLIBCXX_INLINE_VERSION]: Delete.
   (_Vector_base(_Tp_alloc_type&&)) [_GLIBCXX_INLINE_VERSION]: Delete.
   (_Vector_base::_M_create_storage(size_t)): Make protected.
   (vector()): Default.
   (vector(vector&&)): Default.
   (vector(vector&&, const allocator_type&, true_type)): New.
   (vector(vector&&, const allocator_type&, false_type)): New.
   (vector(vector&&, const allocator_type&)): Use latters.
   (vector(_InputIte, _InputIte, const allocator_type&)): Call
   _M_range_initialize directly.
   * include/debug/vector
   (vector(vector&&, const allocator_type&)): Add noexcept qualification.
   * testsuite/23_containers/vector/allocator/default_init.cc: New.
   * testsuite/23_containers/vector/cons/noexcept_move_construct.cc: Add
   static assertions.
On 26/06/2018 15:46, Jonathan Wakely wrote:
> 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.
>
>
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vector.patch
Type: text/x-patch
Size: 13578 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20180627/417c69d3/attachment.bin>
More information about the Libstdc++
mailing list