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