Support Clang's -Wconversion -Wfloat-conversion -Wsign-conversion with -Werror

This commit is contained in:
Ion Gaztañaga committed 2021-10-20 00:18:05 +02:00
1 parent 3e89ec6891
commit 7f35ef420e
11 files changed
+145 -145

No files matched your search

+13 -13
View File
@@ -30,10 +30,10 @@ using boost::move_detail::nanosecond_type;
using namespace boost::container;
template <class POD>
void allocation_timing_test(unsigned int num_iterations, unsigned int num_elements)
void allocation_timing_test(std::size_t num_iterations, std::size_t num_elements)
{
size_t capacity = 0;
unsigned int numalloc = 0, numexpand = 0;
std::size_t numalloc = 0, numexpand = 0;
std::cout
<< " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n"
@@ -52,7 +52,7 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
cpu_timer timer;
timer.resume();
for(unsigned int r = 0; r != num_iterations; ++r){
for(std::size_t r = 0; r != num_iterations; ++r){
void *first_mem = 0;
if(m_mode != BOOST_CONTAINER_EXPAND_FWD)
first_mem = dlmalloc_malloc(sizeof(POD)*num_elements*3/2);
@@ -123,7 +123,7 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
<< float(nseconds)/float(num_iterations*num_elements)
<< std::endl
<< " capacity - alloc calls (new/expand): "
<< (unsigned int)capacity << " - "
<< (std::size_t)capacity << " - "
<< (float(numalloc) + float(numexpand))/float(num_iterations)
<< "(" << float(numalloc)/float(num_iterations) << "/" << float(numexpand)/float(num_iterations) << ")"
<< std::endl << std::endl;
@@ -152,24 +152,24 @@ int allocation_loop()
#define SIMPLE_IT
#ifdef SINGLE_TEST
#ifdef NDEBUG
unsigned int numrep [] = { 50000 };
std::size_t numrep [] = { 50000 };
#else
unsigned int numrep [] = { 5000 };
std::size_t numrep [] = { 5000 };
#endif
unsigned int numele [] = { 100 };
std::size_t numele [] = { 100 };
#elif defined(SIMPLE_IT)
unsigned int numrep [] = { 3 };
unsigned int numele [] = { 100 };
std::size_t numrep [] = { 3 };
std::size_t numele [] = { 100 };
#else
#ifdef NDEBUG
unsigned int numrep [] = { /*10000, */10000, 100000, 1000000 };
std::size_t numrep [] = { /*10000, */10000, 100000, 1000000 };
#else
unsigned int numrep [] = { /*10000, */1000, 10000, 100000 };
std::size_t numrep [] = { /*10000, */1000, 10000, 100000 };
#endif
unsigned int numele [] = { /*10000, */1000, 100, 10 };
std::size_t numele [] = { /*10000, */1000, 100, 10 };
#endif
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
allocation_timing_test<POD>(numrep[i], numele[i]);
}
+21 -21
View File
@@ -101,16 +101,16 @@ void print_header()
}
template<class Allocator>
void vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output)
void vector_test_template(std::size_t num_iterations, std::size_t num_elements, bool csv_output)
{
typedef Allocator IntAllocator;
unsigned int numalloc = 0, numexpand = 0;
std::size_t numalloc = 0, numexpand = 0;
cpu_timer timer;
timer.resume();
unsigned int capacity = 0;
for(unsigned int r = 0; r != num_iterations; ++r){
std::size_t capacity = 0;
for(std::size_t r = 0; r != num_iterations; ++r){
bc::vector<MyInt, IntAllocator> v;
v.reset_alloc_stats();
void *first_mem = 0;
@@ -119,12 +119,12 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
v.push_back(MyInt(0));
bc::dlmalloc_free(first_mem);
for(unsigned int e = 0; e != num_elements; ++e){
v.push_back(MyInt(e));
for(std::size_t e = 0; e != num_elements; ++e){
v.push_back(MyInt((int)e));
}
numalloc += v.num_alloc;
numexpand += v.num_expand_bwd;
capacity = static_cast<unsigned int>(v.capacity());
capacity = static_cast<std::size_t>(v.capacity());
}
BOOST_CATCH(...){
bc::dlmalloc_free(first_mem);
@@ -164,7 +164,7 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
<< float(nseconds)/float(num_iterations*num_elements)
<< std::endl
<< " capacity - alloc calls (new/expand): "
<< (unsigned int)capacity << " - "
<< (std::size_t)capacity << " - "
<< (float(numalloc) + float(numexpand))/float(num_iterations)
<< "(" << float(numalloc)/float(num_iterations) << "/" << float(numexpand)/float(num_iterations) << ")"
<< std::endl;
@@ -181,42 +181,42 @@ int main(int argc, const char *argv[])
#define SIMPLE_IT
#ifdef SINGLE_TEST
#ifdef NDEBUG
unsigned int numit [] = { 10 };
std::size_t numit [] = { 10 };
#else
unsigned int numit [] = { 10 };
std::size_t numit [] = { 10 };
#endif
unsigned int numele [] = { 10000 };
std::size_t numele [] = { 10000 };
#elif defined(SIMPLE_IT)
unsigned int numit [] = { 3 };
unsigned int numele[] = { 10000 };
std::size_t numit [] = { 3 };
std::size_t numele[] = { 10000 };
#else
#ifdef NDEBUG
unsigned int numit [] = { 2000, 20000, 200000, 2000000 };
std::size_t numit [] = { 2000, 20000, 200000, 2000000 };
#else
unsigned int numit [] = { 100, 1000, 10000, 100000 };
std::size_t numit [] = { 100, 1000, 10000, 100000 };
#endif
unsigned int numele [] = { 10000, 1000, 100, 10 };
std::size_t numele [] = { 10000, 1000, 100, 10 };
#endif
bool csv_output = argc == 2 && (strcmp(argv[1], "--csv-output") == 0);
if(csv_output){
print_header();
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
vector_test_template<StdAllocator>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
vector_test_template<AllocatorPlusV1>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
vector_test_template<AllocatorPlusV2Mask>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
vector_test_template<AllocatorPlusV2>(numit[i], numele[i], csv_output);
}
}
else{
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
std::cout << "\n ----------------------------------- \n"
<< " Iterations/Elements: " << numit[i] << "/" << numele[i]
<< "\n ----------------------------------- \n";
+25 -25
View File
@@ -85,15 +85,15 @@ class MyInt
};
template<class Container>
void vector_test_template(unsigned int num_iterations, unsigned int num_elements)
void vector_test_template(std::size_t num_iterations, std::size_t num_elements)
{
unsigned int numalloc = 0, numexpand = 0;
std::size_t numalloc = 0, numexpand = 0;
cpu_timer timer;
timer.resume();
unsigned int capacity = 0;
for(unsigned int r = 0; r != num_iterations; ++r){
std::size_t capacity = 0;
for(std::size_t r = 0; r != num_iterations; ++r){
Container v;
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
reset_alloc_stats(v);
@@ -101,47 +101,47 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
//v.reserve(num_elements);
//MyInt a[3];
/*
for(unsigned int e = 0; e != num_elements/3; ++e){
for(std::size_t e = 0; e != num_elements/3; ++e){
v.insert(v.end(), &a[0], &a[0]+3);
}*/
/*
for(unsigned int e = 0; e != num_elements/3; ++e){
v.insert(v.end(), 3, MyInt(e));
for(std::size_t e = 0; e != num_elements/3; ++e){
v.insert(v.end(), 3, MyInt((int)e));
}*/
/*
for(unsigned int e = 0; e != num_elements/3; ++e){
for(std::size_t e = 0; e != num_elements/3; ++e){
v.insert(v.empty() ? v.end() : --v.end(), &a[0], &a[0]+3);
}*/
/*
for(unsigned int e = 0; e != num_elements/3; ++e){
v.insert(v.empty() ? v.end() : --v.end(), 3, MyInt(e));
for(std::size_t e = 0; e != num_elements/3; ++e){
v.insert(v.empty() ? v.end() : --v.end(), 3, MyInt((int)e));
}*/
/*
for(unsigned int e = 0; e != num_elements/3; ++e){
for(std::size_t e = 0; e != num_elements/3; ++e){
v.insert(v.size() >= 3 ? v.end()-3 : v.begin(), &a[0], &a[0]+3);
}*/
/*
for(unsigned int e = 0; e != num_elements/3; ++e){
v.insert(v.size() >= 3 ? v.end()-3 : v.begin(), 3, MyInt(e));
for(std::size_t e = 0; e != num_elements/3; ++e){
v.insert(v.size() >= 3 ? v.end()-3 : v.begin(), 3, MyInt((int)e));
}*/
/*
for(unsigned int e = 0; e != num_elements; ++e){
v.insert(v.end(), MyInt(e));
for(std::size_t e = 0; e != num_elements; ++e){
v.insert(v.end(), MyInt((int)e));
}*/
/*
for(unsigned int e = 0; e != num_elements; ++e){
v.insert(v.empty() ? v.end() : --v.end(), MyInt(e));
for(std::size_t e = 0; e != num_elements; ++e){
v.insert(v.empty() ? v.end() : --v.end(), MyInt((int)e));
}*/
for(unsigned int e = 0; e != num_elements; ++e){
v.push_back(MyInt(e));
for(std::size_t e = 0; e != num_elements; ++e){
v.push_back(MyInt((int)e));
}
#ifdef BOOST_CONTAINER_VECTOR_ALLOC_STATS
numalloc += get_num_alloc(v);
numexpand += get_num_expand(v);
#endif
capacity = static_cast<unsigned int>(v.capacity());
capacity = static_cast<std::size_t>(v.capacity());
}
timer.stop();
@@ -154,7 +154,7 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
<< float(nseconds)/float(num_iterations*num_elements)
<< std::endl
<< " capacity - alloc calls (new/expand): "
<< (unsigned int)capacity << " - "
<< (std::size_t)capacity << " - "
<< (float(numalloc) + float(numexpand))/float(num_iterations)
<< "(" << float(numalloc)/float(num_iterations) << "/" << float(numexpand)/float(num_iterations) << ")"
<< std::endl << std::endl;
@@ -184,15 +184,15 @@ int main()
std::size_t numele [] = { 10000 };
#else
#ifdef NDEBUG
unsigned int numit [] = { 1000, 10000, 100000, 1000000 };
std::size_t numit [] = { 1000, 10000, 100000, 1000000 };
#else
unsigned int numit [] = { 100, 1000, 10000, 100000 };
std::size_t numit [] = { 100, 1000, 10000, 100000 };
#endif
unsigned int numele [] = { 10000, 1000, 100, 10 };
std::size_t numele [] = { 10000, 1000, 100, 10 };
#endif
print_header();
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
vector_test_template< bc::vector<MyInt, std::allocator<MyInt> > >(numit[i], numele[i]);
vector_test_template< bc::vector<MyInt, bc::allocator<MyInt, 1> > >(numit[i], numele[i]);
vector_test_template<bc::vector<MyInt, bc::allocator<MyInt, 2, bc::expand_bwd | bc::expand_fwd> > >(numit[i], numele[i]);
+19 -19
View File
@@ -33,7 +33,7 @@ namespace bc = boost::container;
class MyInt
{
std::size_t int_; //Use a type that will grow on 64 bit machines
std::ptrdiff_t int_; //Use a type that will grow on 64 bit machines
public:
MyInt(int i = 0) : int_(i){}
@@ -71,13 +71,13 @@ void print_header()
}
template<class Allocator>
void vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output)
void vector_test_template(std::size_t num_iterations, std::size_t num_elements, bool csv_output)
{
typedef Allocator IntAllocator;
unsigned int capacity = 0;
std::size_t capacity = 0;
const std::size_t Step = 5;
unsigned int num_shrink = 0;
std::size_t num_shrink = 0;
(void)capacity;
cpu_timer timer;
@@ -88,12 +88,12 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
<unsigned, bc::dtl::version<Allocator>::value> alloc_version;
#endif
for(unsigned int r = 0; r != num_iterations; ++r){
for(std::size_t r = 0; r != num_iterations; ++r){
bc::vector<MyInt, IntAllocator> v(num_elements);
v.reset_alloc_stats();
num_shrink = 0;
for(unsigned int e = num_elements; e != 0; e -= Step){
v.erase(v.end() - Step, v.end());
for(std::size_t e = num_elements; e != 0; e -= Step){
v.erase(v.end() - std::ptrdiff_t(Step), v.end());
v.shrink_to_fit();
assert( (alloc_version::value != 2) || (e == Step) || (v.num_shrink > num_shrink) );
num_shrink = v.num_shrink;
@@ -136,39 +136,39 @@ int main(int argc, const char *argv[])
#define SIMPLE_IT
#ifdef SINGLE_TEST
#ifdef NDEBUG
unsigned int numit [] = { 10 };
std::size_t numit [] = { 10 };
#else
unsigned int numit [] = { 50 };
unsigned int numele[] = { 2000 };
std::size_t numit [] = { 50 };
std::size_t numele[] = { 2000 };
#endif
#elif defined SIMPLE_IT
unsigned int numit [] = { 3 };
unsigned int numele[] = { 2000 };
std::size_t numit [] = { 3 };
std::size_t numele[] = { 2000 };
#else
#ifdef NDEBUG
unsigned int numit [] = { 100, 1000, 10000 };
std::size_t numit [] = { 100, 1000, 10000 };
#else
unsigned int numit [] = { 10, 100, 1000 };
std::size_t numit [] = { 10, 100, 1000 };
#endif
unsigned int numele [] = { 10000, 2000, 500 };
std::size_t numele [] = { 10000, 2000, 500 };
#endif
bool csv_output = argc == 2 && (strcmp(argv[1], "--csv-output") == 0);
if(csv_output){
print_header();
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
vector_test_template<StdAllocator>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
vector_test_template<AllocatorPlusV1>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
vector_test_template<AllocatorPlusV2>(numit[i], numele[i], csv_output);
}
}
else{
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
std::cout << "\n ----------------------------------- \n"
<< " Iterations/Elements: " << numit[i] << "/" << numele[i]
<< "\n ----------------------------------- \n";
+24 -24
View File
@@ -96,7 +96,7 @@ struct get_stable_vector
};
template<template<class> class GetContainer, class Allocator>
void stable_vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output)
void stable_vector_test_template(std::size_t num_iterations, std::size_t num_elements, bool csv_output)
{
typedef typename GetContainer<Allocator>::type vector_type;
//std::size_t top_capacity = 0;
@@ -107,8 +107,8 @@ void stable_vector_test_template(unsigned int num_iterations, unsigned int num_e
cpu_timer timer;
timer.resume();
for(unsigned int r = 0; r != num_iterations; ++r){
l.insert(l.end(), num_elements, MyInt(r));
for(std::size_t r = 0; r != num_iterations; ++r){
l.insert(l.end(), num_elements, MyInt((int)r));
}
timer.stop();
@@ -138,7 +138,7 @@ void stable_vector_test_template(unsigned int num_iterations, unsigned int num_e
//Now preprocess ranges to erase
std::vector<typename vector_type::iterator> ranges_to_erase;
ranges_to_erase.push_back(l.begin());
for(unsigned int r = 0; r != num_iterations; ++r){
for(std::size_t r = 0; r != num_iterations; ++r){
typename vector_type::iterator next_pos(ranges_to_erase[r]);
std::size_t n = num_elements;
while(n--){ ++next_pos; }
@@ -149,7 +149,7 @@ void stable_vector_test_template(unsigned int num_iterations, unsigned int num_e
timer.stop();
timer.start();
for(unsigned int r = 0; r != num_iterations; ++r){
for(std::size_t r = 0; r != num_iterations; ++r){
std::size_t init_pos = (num_iterations-1)-r;
l.erase(ranges_to_erase[init_pos], l.end());
}
@@ -169,10 +169,10 @@ void stable_vector_test_template(unsigned int num_iterations, unsigned int num_e
<< float(nseconds)/float(num_iterations*num_elements)/*
<< std::endl
<< " max capacity: "
<< static_cast<unsigned int>(top_capacity)
<< static_cast<std::size_t>(top_capacity)
<< std::endl
<< " remaining cap. "
<< static_cast<unsigned int>(top_capacity - num_iterations*num_elements)
<< static_cast<std::size_t>(top_capacity - num_iterations*num_elements)
<< " (" << (float(top_capacity)/float(num_iterations*num_elements) - 1)*100 << " %)"*/
<< std::endl << std::endl;
}
@@ -224,21 +224,21 @@ int main(int argc, const char *argv[])
#define SIMPLE_IT
#ifdef SINGLE_TEST
#ifdef NDEBUG
unsigned int numit [] = { 40 };
std::size_t numit [] = { 40 };
#else
unsigned int numit [] = { 4 };
std::size_t numit [] = { 4 };
#endif
unsigned int numele [] = { 10000 };
std::size_t numele [] = { 10000 };
#elif defined(SIMPLE_IT)
unsigned int numit [] = { 3 };
unsigned int numele [] = { 10000 };
std::size_t numit [] = { 3 };
std::size_t numele [] = { 10000 };
#else
#ifdef NDEBUG
unsigned int numit [] = { 40, 400, 4000, 40000 };
std::size_t numit [] = { 40, 400, 4000, 40000 };
#else
unsigned int numit [] = { 4, 40, 400, 4000 };
std::size_t numit [] = { 4, 40, 400, 4000 };
#endif
unsigned int numele [] = { 10000, 1000, 100, 10 };
std::size_t numele [] = { 10000, 1000, 100, 10 };
#endif
//Warning: range erasure is buggy. Vector iterators are not stable, so it is not
@@ -248,33 +248,33 @@ int main(int argc, const char *argv[])
if(csv_output){
print_header();
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
stable_vector_test_template<get_stable_vector, StdAllocator>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
stable_vector_test_template<get_vector, StdAllocator>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
stable_vector_test_template<get_stable_vector, AllocatorPlusV1>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
stable_vector_test_template<get_vector, AllocatorPlusV1>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
stable_vector_test_template<get_stable_vector, AllocatorPlusV2>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
stable_vector_test_template<get_vector, AllocatorPlusV2>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
stable_vector_test_template<get_stable_vector, AdPool2PercentV2>(numit[i], numele[i], csv_output);
}
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
stable_vector_test_template<get_vector, AdPool2PercentV2>(numit[i], numele[i], csv_output);
}
}
else{
for(unsigned int i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
for(std::size_t i = 0; i < sizeof(numele)/sizeof(numele[0]); ++i){
std::cout << "\n ----------------------------------- \n"
<< " Iterations/Elements: " << numit[i] << "/" << numele[i]
<< "\n ----------------------------------- \n";
+1 -1
View File
@@ -93,7 +93,7 @@ cpu_times time_it()
std::sort(v.begin(), v.end());
sortTime.stop();
rotateTime.resume();
std::rotate(v.begin(), v.begin() + v.size()/2, v.end());
std::rotate(v.begin(), v.begin() + std::ptrdiff_t(v.size()/2), v.end());
rotateTime.stop();
destructionTime.resume();
delete &v;
+1 -1
View File
@@ -177,7 +177,7 @@ struct insert_near_end
{
typedef typename C::iterator it_t;
it_t it (c.end());
it -= static_cast<typename C::size_type>(c.size() >= 2)*2;
it -= static_cast<typename C::difference_type>(c.size() >= 2)*2;
c.insert(it, MyInt(i));
}