Support GCC's -Wconversion -Wfloat-conversion -Warith-conversion -Wsign-conversion warnings.

This commit is contained in:
Ion Gaztañaga
2021-10-16 15:57:47 +02:00
parent 883868e6b2
commit dad2cb2d02
42 changed files with 813 additions and 754 deletions
+47 -41
View File
@@ -94,6 +94,7 @@ class vec_iterator
typedef typename boost::intrusive::pointer_traits<Pointer>::element_type element_type;
#endif
typedef typename boost::intrusive::pointer_traits<Pointer>::difference_type difference_type;
typedef typename boost::intrusive::pointer_traits<Pointer>::size_type size_type;
typedef typename dtl::if_c
< IsConst
, typename boost::intrusive::pointer_traits<Pointer>::template
@@ -194,6 +195,7 @@ class vec_iterator
friend vec_iterator operator-(vec_iterator left, difference_type off) BOOST_NOEXCEPT_OR_NOTHROW
{ BOOST_ASSERT(left.m_ptr || !off); left.m_ptr -= off; return left; }
//Difference
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
friend difference_type operator-(const vec_iterator &left, const vec_iterator& right) BOOST_NOEXCEPT_OR_NOTHROW
{ return left.m_ptr - right.m_ptr; }
@@ -417,10 +419,10 @@ struct vector_alloc_holder
{ this->m_size = static_cast<stored_size_type>(s); }
BOOST_CONTAINER_FORCEINLINE void dec_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW
{ this->m_size -= static_cast<stored_size_type>(s); }
{ this->m_size = static_cast<stored_size_type>(this->m_size - s); }
BOOST_CONTAINER_FORCEINLINE void inc_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW
{ this->m_size += static_cast<stored_size_type>(s); }
{ this->m_size = static_cast<stored_size_type>(this->m_size + s); }
BOOST_CONTAINER_FORCEINLINE void set_stored_capacity(size_type c) BOOST_NOEXCEPT_OR_NOTHROW
{ this->m_capacity = static_cast<stored_size_type>(c); }
@@ -450,7 +452,7 @@ struct vector_alloc_holder
bool try_expand_fwd(size_type at_least)
{
//There is not enough memory, try to expand the old one
const size_type new_cap = this->capacity() + at_least;
const size_type new_cap = size_type(this->capacity() + at_least);
size_type real_cap = new_cap;
pointer reuse = this->start();
bool const success = !!this->allocation_command(expand_fwd, new_cap, real_cap, reuse);
@@ -470,8 +472,8 @@ struct vector_alloc_holder
BOOST_ASSERT(additional_objects > size_type(this->m_capacity - this->m_size));
size_type max = allocator_traits_type::max_size(this->alloc());
(clamp_by_stored_size_type<size_type>)(max, stored_size_type());
const size_type remaining_cap = max - size_type(this->m_capacity);
const size_type min_additional_cap = additional_objects - size_type(this->m_capacity - this->m_size);
const size_type remaining_cap = size_type(max - size_type(this->m_capacity));
const size_type min_additional_cap = size_type(additional_objects - size_type(this->m_capacity - this->m_size));
if ( remaining_cap < min_additional_cap )
boost::container::throw_length_error("get_next_capacity, allocator's max size reached");
@@ -647,10 +649,10 @@ struct vector_alloc_holder<Allocator, StoredSizeType, version_0>
{ this->m_size = static_cast<stored_size_type>(s); }
BOOST_CONTAINER_FORCEINLINE void dec_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW
{ this->m_size -= static_cast<stored_size_type>(s); }
{ this->m_size = static_cast<stored_size_type>(this->m_size - s); }
BOOST_CONTAINER_FORCEINLINE void inc_stored_size(size_type s) BOOST_NOEXCEPT_OR_NOTHROW
{ this->m_size += static_cast<stored_size_type>(s); }
{ this->m_size = static_cast<stored_size_type>(this->m_size + s); }
BOOST_CONTAINER_FORCEINLINE void priv_first_allocation(size_type cap)
{
@@ -813,7 +815,7 @@ private:
private:
BOOST_COPYABLE_AND_MOVABLE(vector)
typedef vector_value_traits<allocator_type> value_traits;
typedef constant_iterator<T, difference_type> cvalue_iterator;
typedef constant_iterator<T> cvalue_iterator;
protected:
@@ -1290,9 +1292,10 @@ private:
>::type * = 0)
)
{
typedef typename iterator_traits<FwdIt>::size_type it_size_type;
//For Fwd iterators the standard only requires EmplaceConstructible and assignable from *first
//so we can't do any backwards allocation
const typename iterator_traits<FwdIt>::size_type sz = boost::container::iterator_distance(first, last);
const it_size_type sz = boost::container::iterator_udistance(first, last);
if (sz > size_type(-1)){
boost::container::throw_length_error("vector::assign, FwdIt's max length reached");
}
@@ -1400,7 +1403,7 @@ private:
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE iterator end() BOOST_NOEXCEPT_OR_NOTHROW
{
iterator it (this->m_holder.start());
it += this->m_holder.m_size;
it += difference_type(this->m_holder.m_size);
return it; //Adding zero to null pointer is allowed (non-UB)
}
@@ -1464,7 +1467,7 @@ private:
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE const_iterator cend() const BOOST_NOEXCEPT_OR_NOTHROW
{
const_iterator it (this->m_holder.start());
it += this->m_holder.m_size;
it += difference_type(this->m_holder.m_size);
return it; //Adding zero to null pointer is allowed (non-UB)
}
@@ -1621,7 +1624,7 @@ private:
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE reference back() BOOST_NOEXCEPT_OR_NOTHROW
{
BOOST_ASSERT(!this->empty());
return this->m_holder.start()[this->m_holder.m_size - 1];
return this->m_holder.start()[difference_type(this->m_holder.m_size - 1u)];
}
//! <b>Requires</b>: !empty()
@@ -1649,7 +1652,7 @@ private:
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE reference operator[](size_type n) BOOST_NOEXCEPT_OR_NOTHROW
{
BOOST_ASSERT(this->m_holder.m_size > n);
return this->m_holder.start()[n];
return this->m_holder.start()[difference_type(n)];
}
//! <b>Requires</b>: size() > n.
@@ -1682,7 +1685,7 @@ private:
iterator nth(size_type n) BOOST_NOEXCEPT_OR_NOTHROW
{
BOOST_ASSERT(this->m_holder.m_size >= n);
return iterator(this->m_holder.start()+n);
return iterator(this->m_holder.start()+difference_type(n));
}
//! <b>Requires</b>: size() >= n.
@@ -1700,7 +1703,7 @@ private:
const_iterator nth(size_type n) const BOOST_NOEXCEPT_OR_NOTHROW
{
BOOST_ASSERT(this->m_holder.m_size >= n);
return const_iterator(this->m_holder.start()+n);
return const_iterator(this->m_holder.start()+difference_type(n));
}
//! <b>Requires</b>: begin() <= p <= end().
@@ -1990,13 +1993,13 @@ private:
)
{
BOOST_ASSERT(this->priv_in_range_or_end(pos));
const size_type n_pos = pos - this->cbegin();
const size_type n_pos = size_type(pos - this->cbegin());
iterator it(vector_iterator_get_ptr(pos));
for(;first != last; ++first){
it = this->emplace(it, *first);
++it;
}
return iterator(this->m_holder.start() + n_pos);
return iterator(this->m_holder.start() + difference_type(n_pos));
}
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
@@ -2009,8 +2012,9 @@ private:
>::type * = 0
)
{
typedef typename iterator_traits<FwdIt>::size_type it_size_type;
BOOST_ASSERT(this->priv_in_range_or_end(pos));
const typename iterator_traits<FwdIt>::size_type sz = boost::container::iterator_distance(first, last);
const it_size_type sz = boost::container::iterator_udistance(first, last);
if (sz > size_type(-1)){
boost::container::throw_length_error("vector::insert, FwdIt's max length reached");
}
@@ -2041,7 +2045,7 @@ private:
{
BOOST_ASSERT(this->priv_in_range_or_end(pos));
BOOST_ASSERT(dtl::is_input_iterator<InIt>::value ||
num == static_cast<size_type>(boost::container::iterator_distance(first, last)));
num == boost::container::iterator_udistance(first, last));
(void)last;
dtl::insert_range_proxy<allocator_type, InIt, T*> proxy(first);
return this->priv_insert_forward_range(vector_iterator_get_ptr(pos), num, proxy);
@@ -2223,7 +2227,7 @@ private:
bool stable_reserve(size_type new_cap)
{
const size_type cp = this->capacity();
return cp >= new_cap || (alloc_version::value == 2 && this->m_holder.try_expand_fwd(new_cap - cp));
return cp >= new_cap || (alloc_version::value == 2 && this->m_holder.try_expand_fwd(size_type(new_cap - cp)));
}
//Absolutely experimental. This function might change, disappear or simply crash!
@@ -2247,7 +2251,7 @@ private:
size_type const free_cap = c - s;
//If not input iterator and new elements don't fit in the remaining capacity, merge in new buffer
if(!dtl::is_input_iterator<InputIt>::value &&
free_cap < (n = static_cast<size_type>(boost::container::iterator_distance(first, last)))){
free_cap < (n = boost::container::iterator_udistance(first, last))){
this->priv_merge_in_new_buffer(first, n, comp, alloc_version());
}
else{
@@ -2433,12 +2437,12 @@ private:
{ return this->m_holder.m_size != this->m_holder.capacity(); }
BOOST_CONTAINER_FORCEINLINE pointer back_ptr() const
{ return this->m_holder.start() + this->m_holder.m_size; }
{ return this->m_holder.start() + difference_type(this->m_holder.m_size); }
BOOST_CONTAINER_FORCEINLINE size_type priv_index_of(pointer p) const
{
BOOST_ASSERT(this->m_holder.start() <= p);
BOOST_ASSERT(p <= (this->m_holder.start()+this->size()));
BOOST_ASSERT(p <= (this->m_holder.start()+difference_type(this->size())));
return static_cast<size_type>(p - this->m_holder.start());
}
@@ -2622,7 +2626,7 @@ private:
++this->num_expand_bwd;
#endif
this->priv_insert_forward_range_expand_backwards
( new_mem , real_cap, ins_pos, 0, this->priv_dummy_empty_proxy());
( new_mem, real_cap, ins_pos, 0, this->priv_dummy_empty_proxy());
}
else{ //New buffer
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
@@ -2750,7 +2754,7 @@ private:
++this->num_alloc;
#endif
this->priv_insert_forward_range_new_allocation(new_buf, new_cap, raw_pos, n, insert_range_proxy);
return iterator(this->m_holder.start() + n_pos);
return iterator(this->m_holder.start() + difference_type(n_pos));
}
template <class InsertionProxy>
@@ -2758,14 +2762,14 @@ private:
(T *const raw_pos, const size_type n, const InsertionProxy insert_range_proxy, version_2)
{
//Check if we have enough memory or try to expand current memory
const size_type n_pos = raw_pos - this->priv_raw_begin();
const size_type n_pos = size_type(raw_pos - this->priv_raw_begin());
//There is not enough memory, allocate a new
//buffer or expand the old one.
size_type real_cap = this->m_holder.template next_capacity<growth_factor_type>(n);
pointer reuse(this->m_holder.start());
pointer const ret (this->m_holder.allocation_command
(allocate_new | expand_fwd | expand_bwd, this->m_holder.m_size + n, real_cap, reuse));
(allocate_new | expand_fwd | expand_bwd, size_type(this->m_holder.m_size + n), real_cap, reuse));
//Buffer reallocated
if(reuse){
@@ -2797,7 +2801,7 @@ private:
( boost::movelib::to_raw_pointer(ret), real_cap, raw_pos, n, insert_range_proxy);
}
return iterator(this->m_holder.start() + n_pos);
return iterator(this->m_holder.start() + (difference_type)(n_pos));
}
template <class InsertionProxy>
@@ -2843,10 +2847,10 @@ private:
const size_type sz = this->m_holder.m_size;
if (new_size < sz){
//Destroy last elements
this->priv_destroy_last_n(sz - new_size);
this->priv_destroy_last_n(size_type(sz - new_size));
}
else {
this->priv_insert_forward_range(this->back_ptr(), new_size - sz, this->priv_resize_proxy(u));
this->priv_insert_forward_range(this->back_ptr(), size_type(new_size - sz), this->priv_resize_proxy(u));
}
}
@@ -2922,7 +2926,9 @@ private:
//All uninitialized_moved
::boost::container::uninitialized_move_alloc
(this->m_holder.alloc(), first_ptr, last_ptr, first_ptr + shift_count);
hole_size = first_pos + shift_count - limit_pos;
//Cast in case size_type is narrower than int, promotions are applied
//and Wconversion is in place
hole_size = static_cast<size_type>(first_pos + shift_count - limit_pos);
}
//Case C:
else{
@@ -3024,7 +3030,7 @@ private:
//We can have 8 possibilities:
const size_type elemsbefore = static_cast<size_type>(pos - old_start);
const size_type s_before = static_cast<size_type>(old_start - new_start);
const size_type before_plus_new = elemsbefore + n;
const size_type before_plus_new = size_type(elemsbefore + n);
typedef typename value_traits::ArrayDestructor array_destructor_t;
@@ -3039,7 +3045,7 @@ private:
this->m_holder.set_stored_size(elemsbefore);
insert_range_proxy.uninitialized_copy_n_and_update(a, new_elem_pos, n);
this->m_holder.set_stored_size(before_plus_new);
const size_type new_size = old_size + n;
const size_type new_size = size_type(old_size + n);
//Check if s_before is so big that even copying the old data + new data
//there is a gap between the new data and the old data
if(s_before >= new_size){
@@ -3174,7 +3180,7 @@ private:
old_values_destroyer.shrink_forward(old_size - (s_before - n));
}
}
this->m_holder.set_stored_size(old_size + new_1st_range);
this->m_holder.set_stored_size(size_type(old_size + new_1st_range));
//Now copy the second part of old_begin overwriting itself
T *const next = ::boost::container::move(old_start + s_before, pos, old_start);
//Now copy the new_beg elements
@@ -3216,11 +3222,11 @@ private:
T * const new_pos = ::boost::container::uninitialized_move_alloc
(a, old_start, pos, new_start);
this->m_holder.set_stored_size(elemsbefore);
const size_type mid_n = s_before - elemsbefore;
const size_type mid_n = size_type(s_before - elemsbefore);
insert_range_proxy.uninitialized_copy_n_and_update(a, new_pos, mid_n);
//The buffer is all constructed until old_end,
//release destroyer
this->m_holder.set_stored_size(old_size + s_before);
this->m_holder.set_stored_size(size_type(old_size + s_before));
old_values_destroyer.release();
if(do_after){
@@ -3229,7 +3235,7 @@ private:
}
else{
//Copy all new elements
const size_type rest_new = n - mid_n;
const size_type rest_new = size_type(n - mid_n);
insert_range_proxy.copy_n_and_update(a, old_start, rest_new);
T* const move_start = old_start + rest_new;
@@ -3240,7 +3246,7 @@ private:
//trivial_dctr_after_move is true
//Destroy remaining moved elements from old_end except if they
//have trivial destructor after being moved
const size_type n_destroy = s_before - n;
const size_type n_destroy = size_type(s_before - n);
BOOST_IF_CONSTEXPR(!value_traits::trivial_dctr_after_move){
boost::container::destroy_alloc_n(a, move_end, n_destroy);
}
@@ -3267,8 +3273,8 @@ private:
//| old_begin + new | old_end |raw |
//|_______________________________________|_________|____|
//
const size_type n_after = n - s_before;
const size_type elemsafter = old_size - elemsbefore;
const size_type n_after = size_type(n - s_before);
const size_type elemsafter = size_type(old_size - elemsbefore);
//We can have two situations:
if (elemsafter >= n_after){
@@ -3308,7 +3314,7 @@ private:
//|__________________________|_______________|________|_________|
//First initialize data in raw memory
const size_type mid_last_dist = n_after - elemsafter;
const size_type mid_last_dist = size_type(n_after - elemsafter);
//Copy to the old_end part to the uninitialized zone leaving a gap.
::boost::container::uninitialized_move_alloc(a, pos, old_finish, old_finish + mid_last_dist);