forked from boostorg/unordered
Fix signed conversion warnings.
This commit is contained in:
@ -490,7 +490,7 @@ namespace boost { namespace unordered { namespace detail {
|
||||
{
|
||||
if(i == j) return;
|
||||
|
||||
std::size_t distance = std::distance(i, j);
|
||||
std::size_t distance = static_cast<std::size_t>(std::distance(i, j));
|
||||
if(distance == 1) {
|
||||
emplace_impl(
|
||||
boost::unordered::detail::func::construct_value(
|
||||
|
@ -128,7 +128,7 @@ namespace boost { namespace unordered { namespace detail {
|
||||
inline std::size_t insert_size(I i, I j, typename
|
||||
boost::unordered::detail::enable_if_forward<I, void*>::type = 0)
|
||||
{
|
||||
return std::distance(i, j);
|
||||
return static_cast<std::size_t>(std::distance(i, j));
|
||||
}
|
||||
|
||||
template <class I>
|
||||
|
@ -11,9 +11,9 @@ project unordered-test/unordered
|
||||
<toolset>intel:<warnings>on
|
||||
# Would be nice to define -Wundef, but I'm getting warnings from
|
||||
# Boost.Preprocessor on trunk.
|
||||
<toolset>gcc:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow"
|
||||
<toolset>darwin:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow"
|
||||
<toolset>clang:<cxxflags>"-pedantic -Wextra"
|
||||
<toolset>gcc:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wsign-conversion -Wconversion -Wfloat-equal -Wshadow"
|
||||
<toolset>darwin:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wsign-conversion -Wconversion -Wfloat-equal -Wshadow"
|
||||
<toolset>clang:<cxxflags>"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wsign-conversion -Wconversion -Wfloat-equal -Wshadow"
|
||||
;
|
||||
|
||||
#alias framework : /boost/test//boost_unit_test_framework ;
|
||||
|
@ -17,7 +17,7 @@ template <class T>
|
||||
struct self_assign_base : public test::exception_base
|
||||
{
|
||||
test::random_values<T> values;
|
||||
self_assign_base(int count = 0) : values(count) {}
|
||||
self_assign_base(std::size_t count = 0) : values(count) {}
|
||||
|
||||
typedef T data_type;
|
||||
T init() const { return T(values.begin(), values.end()); }
|
||||
|
@ -17,7 +17,7 @@ template <class T>
|
||||
struct self_swap_base : public test::exception_base
|
||||
{
|
||||
test::random_values<T> values;
|
||||
self_swap_base(int count = 0) : values(count) {}
|
||||
self_swap_base(std::size_t count = 0) : values(count) {}
|
||||
|
||||
typedef T data_type;
|
||||
T init() const { return T(values.begin(), values.end()); }
|
||||
|
@ -105,13 +105,13 @@ namespace test
|
||||
{
|
||||
random_values() {}
|
||||
|
||||
explicit random_values(int count, test::random_generator const& generator =
|
||||
explicit random_values(std::size_t count, test::random_generator const& generator =
|
||||
test::default_generator)
|
||||
{
|
||||
fill(count, generator);
|
||||
}
|
||||
|
||||
void fill(int count, test::random_generator const& generator =
|
||||
void fill(std::size_t count, test::random_generator const& generator =
|
||||
test::default_generator)
|
||||
{
|
||||
test::unordered_generator<X> gen(generator);
|
||||
|
@ -146,14 +146,16 @@ namespace exception
|
||||
UNORDERED_EPOINT("Mock hash function.");
|
||||
}
|
||||
|
||||
int result;
|
||||
switch(tag_) {
|
||||
case 1:
|
||||
return x.tag1_;
|
||||
result = x.tag1_;
|
||||
case 2:
|
||||
return x.tag2_;
|
||||
result = x.tag2_;
|
||||
default:
|
||||
return x.tag1_ + x.tag2_;
|
||||
result = x.tag1_ + x.tag2_;
|
||||
}
|
||||
return static_cast<std::size_t>(result);
|
||||
}
|
||||
|
||||
friend bool operator==(hash const& x1, hash const& x2) {
|
||||
|
@ -182,29 +182,42 @@ namespace test
|
||||
explicit hash(int t = 0) : type_(t) {}
|
||||
|
||||
std::size_t operator()(object const& x) const {
|
||||
int result;
|
||||
switch(type_) {
|
||||
case 1:
|
||||
return x.tag1_;
|
||||
result = x.tag1_;
|
||||
case 2:
|
||||
return x.tag2_;
|
||||
result = x.tag2_;
|
||||
default:
|
||||
return x.tag1_ + x.tag2_;
|
||||
result = x.tag1_ + x.tag2_;
|
||||
}
|
||||
return static_cast<std::size_t>(result);
|
||||
}
|
||||
|
||||
std::size_t operator()(movable const& x) const {
|
||||
int result;
|
||||
switch(type_) {
|
||||
case 1:
|
||||
return x.tag1_;
|
||||
result = x.tag1_;
|
||||
case 2:
|
||||
return x.tag2_;
|
||||
result = x.tag2_;
|
||||
default:
|
||||
return x.tag1_ + x.tag2_;
|
||||
result = x.tag1_ + x.tag2_;
|
||||
}
|
||||
return static_cast<std::size_t>(result);
|
||||
}
|
||||
|
||||
std::size_t operator()(int x) const {
|
||||
return x;
|
||||
int result;
|
||||
switch(type_) {
|
||||
case 1:
|
||||
result = x;
|
||||
case 2:
|
||||
result = x * 7;
|
||||
default:
|
||||
result = x * 256;
|
||||
}
|
||||
return static_cast<std::size_t>(result);
|
||||
}
|
||||
|
||||
friend bool operator==(hash const& x1, hash const& x2) {
|
||||
|
@ -89,8 +89,9 @@ void container_test(X& r, T const&)
|
||||
|
||||
// size_type can represent any non-negative value type of difference_type
|
||||
// I'm not sure about either of these tests...
|
||||
size_type max_diff((std::numeric_limits<difference_type>::max)());
|
||||
difference_type converted_diff(max_diff);
|
||||
size_type max_diff = static_cast<size_type>(
|
||||
(std::numeric_limits<difference_type>::max)());
|
||||
difference_type converted_diff(static_cast<difference_type>(max_diff));
|
||||
BOOST_TEST((std::numeric_limits<difference_type>::max)()
|
||||
== converted_diff);
|
||||
|
||||
|
@ -25,9 +25,11 @@ namespace equality_tests
|
||||
return x % 1000 == y % 1000;
|
||||
}
|
||||
|
||||
int operator()(int x) const
|
||||
std::size_t operator()(int x) const
|
||||
{
|
||||
return alt_hash_ ? x % 250 : (x + 5) % 250;
|
||||
return alt_hash_ ?
|
||||
static_cast<std::size_t>(x % 250) :
|
||||
static_cast<std::size_t>((x + 5) % 250);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -43,19 +43,19 @@ void write_container(Container const& x)
|
||||
// Make everything collide - for testing erase in a single bucket.
|
||||
struct collision_hash
|
||||
{
|
||||
int operator()(int) const { return 0; }
|
||||
std::size_t operator()(int) const { return 0; }
|
||||
};
|
||||
|
||||
// For testing erase in 2 buckets.
|
||||
struct collision2_hash
|
||||
{
|
||||
int operator()(int x) const { return x & 1; }
|
||||
std::size_t operator()(int x) const { return static_cast<std::size_t>(x & 1); }
|
||||
};
|
||||
|
||||
// For testing erase in lots of buckets.
|
||||
struct collision3_hash
|
||||
{
|
||||
int operator()(int x) const { return x; }
|
||||
std::size_t operator()(int x) const { return static_cast<std::size_t>(x); }
|
||||
};
|
||||
|
||||
typedef boost::unordered_multimap<int, int,
|
||||
|
@ -25,9 +25,9 @@ namespace erase_tests
|
||||
|
||||
test::seed_t initialize_seed(85638);
|
||||
|
||||
int random_value(int max) {
|
||||
std::size_t random_value(std::size_t max) {
|
||||
using namespace std;
|
||||
return rand() % max;
|
||||
return static_cast<std::size_t>(rand()) % max;
|
||||
}
|
||||
|
||||
template <class Container>
|
||||
@ -35,6 +35,7 @@ void erase_tests1(Container*, test::random_generator generator)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::const_iterator c_iterator;
|
||||
typedef BOOST_DEDUCED_TYPENAME Container::difference_type difference_type;
|
||||
|
||||
std::cerr<<"Erase by key.\n";
|
||||
{
|
||||
@ -89,7 +90,7 @@ void erase_tests1(Container*, test::random_generator generator)
|
||||
int iterations = 0;
|
||||
while(size > 0 && !x.empty())
|
||||
{
|
||||
int index = random_value((int) x.size());
|
||||
std::size_t index = random_value(x.size());
|
||||
c_iterator prev, pos, next;
|
||||
if(index == 0) {
|
||||
prev = pos = x.begin();
|
||||
@ -162,12 +163,14 @@ void erase_tests1(Container*, test::random_generator generator)
|
||||
iterators.push_back(x.cend());
|
||||
|
||||
while(iterators.size() > 1) {
|
||||
int start = random_value((int) iterators.size());
|
||||
int length = random_value((int) (iterators.size() - start));
|
||||
std::size_t start = random_value(iterators.size());
|
||||
std::size_t length = random_value(iterators.size() - start);
|
||||
x.erase(iterators[start], iterators[start + length]);
|
||||
iterators.erase(
|
||||
boost::next(iterators.begin(), start),
|
||||
boost::next(iterators.begin(), start + length));
|
||||
boost::next(iterators.begin(),
|
||||
static_cast<difference_type>(start)),
|
||||
boost::next(iterators.begin(),
|
||||
static_cast<difference_type>(start + length)));
|
||||
|
||||
BOOST_TEST(x.size() == iterators.size() - 1);
|
||||
BOOST_DEDUCED_TYPENAME std::vector<c_iterator>::const_iterator
|
||||
@ -216,7 +219,7 @@ void erase_tests1(Container*, test::random_generator generator)
|
||||
int iterations = 0;
|
||||
while(size > 0 && !x.empty())
|
||||
{
|
||||
int index = random_value((int) x.size());
|
||||
std::size_t index = random_value(x.size());
|
||||
BOOST_DEDUCED_TYPENAME Container::const_iterator prev, pos, next;
|
||||
if(index == 0) {
|
||||
prev = pos = x.begin();
|
||||
|
@ -24,9 +24,9 @@ namespace insert_tests {
|
||||
|
||||
test::seed_t initialize_seed(243432);
|
||||
|
||||
int random_value(int max) {
|
||||
std::size_t random_value(std::size_t max) {
|
||||
using namespace std;
|
||||
return rand() % max;
|
||||
return static_cast<std::size_t>(rand()) % max;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
@ -319,7 +319,7 @@ void insert_tests2(X*, test::random_generator generator)
|
||||
|
||||
BOOST_DEDUCED_TYPENAME test::random_values<X>::iterator
|
||||
next = it;
|
||||
for (int j = random_value(20); j > 0; ++j) {
|
||||
for (std::size_t j = random_value(20); j > 0; ++j) {
|
||||
++next;
|
||||
if (next == v.end()) { break; }
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ void reserve_test1(X*, test::random_generator generator)
|
||||
{
|
||||
for (int random_mlf = 0; random_mlf < 2; ++random_mlf)
|
||||
{
|
||||
for (int i = 1; i < 2000; i += i < 50 ? 1 : 13)
|
||||
for (std::size_t i = 1; i < 2000; i += i < 50 ? 1 : 13)
|
||||
{
|
||||
test::random_values<X> v(i, generator);
|
||||
|
||||
@ -171,7 +171,7 @@ void reserve_test2(X*, test::random_generator generator)
|
||||
{
|
||||
for (int random_mlf = 0; random_mlf < 2; ++random_mlf)
|
||||
{
|
||||
for (int i = 0; i < 2000; i += i < 50 ? 1 : 13)
|
||||
for (std::size_t i = 0; i < 2000; i += i < 50 ? 1 : 13)
|
||||
{
|
||||
test::random_values<X> v(i, generator);
|
||||
|
||||
|
@ -115,7 +115,7 @@ namespace unnecessary_copy_tests
|
||||
#endif
|
||||
{
|
||||
std::size_t hash_value(unnecessary_copy_tests::count_copies const& x) {
|
||||
return x.tag_;
|
||||
return static_cast<std::size_t>(x.tag_);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user