diff --git a/include/boost/unordered/detail/equivalent.hpp b/include/boost/unordered/detail/equivalent.hpp index 45cd026d..5835884a 100644 --- a/include/boost/unordered/detail/equivalent.hpp +++ b/include/boost/unordered/detail/equivalent.hpp @@ -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::distance(i, j)); if(distance == 1) { emplace_impl( boost::unordered::detail::func::construct_value( diff --git a/include/boost/unordered/detail/util.hpp b/include/boost/unordered/detail/util.hpp index 0a406c85..cd722e44 100644 --- a/include/boost/unordered/detail/util.hpp +++ b/include/boost/unordered/detail/util.hpp @@ -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::type = 0) { - return std::distance(i, j); + return static_cast(std::distance(i, j)); } template diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 307dfe1a..065cdefa 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -11,9 +11,9 @@ project unordered-test/unordered intel:on # Would be nice to define -Wundef, but I'm getting warnings from # Boost.Preprocessor on trunk. - gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" - darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wconversion -Wfloat-equal -Wshadow" - clang:"-pedantic -Wextra" + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wsign-conversion -Wconversion -Wfloat-equal -Wshadow" + darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wsign-conversion -Wconversion -Wfloat-equal -Wshadow" + clang:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter -Wsign-conversion -Wconversion -Wfloat-equal -Wshadow" ; #alias framework : /boost/test//boost_unit_test_framework ; diff --git a/test/exception/assign_exception_tests.cpp b/test/exception/assign_exception_tests.cpp index 486bd03c..e8304ee9 100644 --- a/test/exception/assign_exception_tests.cpp +++ b/test/exception/assign_exception_tests.cpp @@ -17,7 +17,7 @@ template struct self_assign_base : public test::exception_base { test::random_values 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()); } diff --git a/test/exception/swap_exception_tests.cpp b/test/exception/swap_exception_tests.cpp index 5e1cd084..0873093a 100644 --- a/test/exception/swap_exception_tests.cpp +++ b/test/exception/swap_exception_tests.cpp @@ -17,7 +17,7 @@ template struct self_swap_base : public test::exception_base { test::random_values 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()); } diff --git a/test/helpers/random_values.hpp b/test/helpers/random_values.hpp index b65a29b2..e22eb36c 100644 --- a/test/helpers/random_values.hpp +++ b/test/helpers/random_values.hpp @@ -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 gen(generator); diff --git a/test/objects/exception.hpp b/test/objects/exception.hpp index 034f31b2..b3c4bacb 100644 --- a/test/objects/exception.hpp +++ b/test/objects/exception.hpp @@ -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(result); } friend bool operator==(hash const& x1, hash const& x2) { diff --git a/test/objects/test.hpp b/test/objects/test.hpp index f6b03db7..ae6e90a7 100644 --- a/test/objects/test.hpp +++ b/test/objects/test.hpp @@ -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(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(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(result); } friend bool operator==(hash const& x1, hash const& x2) { diff --git a/test/unordered/compile_tests.hpp b/test/unordered/compile_tests.hpp index 12c72c9e..7e475432 100644 --- a/test/unordered/compile_tests.hpp +++ b/test/unordered/compile_tests.hpp @@ -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::max)()); - difference_type converted_diff(max_diff); + size_type max_diff = static_cast( + (std::numeric_limits::max)()); + difference_type converted_diff(static_cast(max_diff)); BOOST_TEST((std::numeric_limits::max)() == converted_diff); diff --git a/test/unordered/equality_tests.cpp b/test/unordered/equality_tests.cpp index b6d146c6..4dc6bb1e 100644 --- a/test/unordered/equality_tests.cpp +++ b/test/unordered/equality_tests.cpp @@ -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(x % 250) : + static_cast((x + 5) % 250); } }; diff --git a/test/unordered/erase_equiv_tests.cpp b/test/unordered/erase_equiv_tests.cpp index c81a9ad9..26da1455 100644 --- a/test/unordered/erase_equiv_tests.cpp +++ b/test/unordered/erase_equiv_tests.cpp @@ -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(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(x); } }; typedef boost::unordered_multimap(rand()) % max; } template @@ -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(start)), + boost::next(iterators.begin(), + static_cast(start + length))); BOOST_TEST(x.size() == iterators.size() - 1); BOOST_DEDUCED_TYPENAME std::vector::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(); diff --git a/test/unordered/insert_tests.cpp b/test/unordered/insert_tests.cpp index 83ec15f9..8d1a189b 100644 --- a/test/unordered/insert_tests.cpp +++ b/test/unordered/insert_tests.cpp @@ -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(rand()) % max; } template @@ -319,7 +319,7 @@ void insert_tests2(X*, test::random_generator generator) BOOST_DEDUCED_TYPENAME test::random_values::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; } } diff --git a/test/unordered/rehash_tests.cpp b/test/unordered/rehash_tests.cpp index 551b79fa..122815d3 100644 --- a/test/unordered/rehash_tests.cpp +++ b/test/unordered/rehash_tests.cpp @@ -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 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 v(i, generator); diff --git a/test/unordered/unnecessary_copy_tests.cpp b/test/unordered/unnecessary_copy_tests.cpp index f2b5e892..cb1346ba 100644 --- a/test/unordered/unnecessary_copy_tests.cpp +++ b/test/unordered/unnecessary_copy_tests.cpp @@ -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(x.tag_); } }