From ba5c383877cfc274814c0a252fdc4d188d989912 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 10 Nov 2009 08:15:55 +0000 Subject: [PATCH] Stricter warnings for unordered and hash. There are still warnings in hash_complex_test. [SVN r57537] --- test/exception/Jamfile.v2 | 13 +++++- test/exception/assign_exception_tests.cpp | 4 ++ test/exception/swap_exception_tests.cpp | 4 ++ test/helpers/exception_test.hpp | 3 ++ test/helpers/input_iterator.hpp | 2 + test/helpers/list.hpp | 19 ++++++++- test/helpers/strong.hpp | 2 +- test/helpers/tracker.hpp | 4 +- test/unordered/Jamfile.v2 | 10 +++-- test/unordered/equality_tests.cpp | 52 +++++++++++------------ test/unordered/erase_tests.cpp | 2 +- 11 files changed, 80 insertions(+), 35 deletions(-) diff --git a/test/exception/Jamfile.v2 b/test/exception/Jamfile.v2 index a8508588..3fc78437 100644 --- a/test/exception/Jamfile.v2 +++ b/test/exception/Jamfile.v2 @@ -8,7 +8,18 @@ import testing ; #alias framework : /boost/test//boost_unit_test_framework ; alias framework : ; -project unordered-test/exception-tests ; +project unordered-test/exception-tests + : requirements + all + intel:on + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter" + darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter" + gcc:_GLIBCXX_DEBUG + darwin:_GLIBCXX_DEBUG + msvc:on + gcc:on + darwin:on + ; test-suite unordered-exception : diff --git a/test/exception/assign_exception_tests.cpp b/test/exception/assign_exception_tests.cpp index ebf7ac0e..f059e0f7 100644 --- a/test/exception/assign_exception_tests.cpp +++ b/test/exception/assign_exception_tests.cpp @@ -7,6 +7,10 @@ #include "../helpers/random_values.hpp" #include "../helpers/invariants.hpp" +#if defined(BOOST_MSVC) +#pragma warning(disable:4512) // assignment operator could not be generated +#endif + test::seed_t seed(12847); template diff --git a/test/exception/swap_exception_tests.cpp b/test/exception/swap_exception_tests.cpp index 2025b8bd..e884cb11 100644 --- a/test/exception/swap_exception_tests.cpp +++ b/test/exception/swap_exception_tests.cpp @@ -7,6 +7,10 @@ #include "../helpers/random_values.hpp" #include "../helpers/invariants.hpp" +#if defined(BOOST_MSVC) +#pragma warning(disable:4512) // assignment operator could not be generated +#endif + test::seed_t seed(9387); template diff --git a/test/helpers/exception_test.hpp b/test/helpers/exception_test.hpp index a235526c..e64d168c 100644 --- a/test/helpers/exception_test.hpp +++ b/test/helpers/exception_test.hpp @@ -143,6 +143,9 @@ namespace test { class test_runner { Test const& test_; + + test_runner(test_runner const&); + test_runner& operator=(test_runner const&); public: test_runner(Test const& t) : test_(t) {} void operator()() const { diff --git a/test/helpers/input_iterator.hpp b/test/helpers/input_iterator.hpp index d81d9fec..9e962baa 100644 --- a/test/helpers/input_iterator.hpp +++ b/test/helpers/input_iterator.hpp @@ -21,6 +21,8 @@ namespace test operator value_type const&() const { return v_; } value_type v_; + private: + proxy& operator=(proxy const&); }; template diff --git a/test/helpers/list.hpp b/test/helpers/list.hpp index 128386e0..3b59ce3e 100644 --- a/test/helpers/list.hpp +++ b/test/helpers/list.hpp @@ -17,6 +17,23 @@ namespace test { + template + bool equal(It1 begin, It1 end, It2 compare) + { + for(;begin != end; ++begin, ++compare) + if(*begin != *compare) return false; + return true; + } + + template + bool equal(It1 begin, It1 end, It2 compare, Pred predicate) + { + for(;begin != end; ++begin, ++compare) + if(!predicate(*begin, *compare)) return false; + return true; + } + + template class list; namespace test_detail @@ -222,7 +239,7 @@ namespace test bool operator==(list const& y) const { return size() == y.size() && - std::equal(begin(), end(), y.begin()); + test::equal(begin(), end(), y.begin()); } bool operator!=(list const& y) const { diff --git a/test/helpers/strong.hpp b/test/helpers/strong.hpp index a297fe07..f525faf7 100644 --- a/test/helpers/strong.hpp +++ b/test/helpers/strong.hpp @@ -31,7 +31,7 @@ namespace test void test(X const& x, unsigned int allocations = 0) const { if(!(x.size() == values_.size() && - std::equal(x.cbegin(), x.cend(), values_.begin(), + test::equal(x.cbegin(), x.cend(), values_.begin(), test::equivalent))) BOOST_ERROR("Strong exception safety failure."); if(allocations != allocations_) diff --git a/test/helpers/tracker.hpp b/test/helpers/tracker.hpp index bf6417aa..b5bf3c22 100644 --- a/test/helpers/tracker.hpp +++ b/test/helpers/tracker.hpp @@ -50,7 +50,7 @@ namespace test values1.sort(); values2.sort(); BOOST_TEST(values1.size() == values2.size() && - std::equal(values1.begin(), values1.end(), values2.begin(), + test::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent)); } @@ -62,7 +62,7 @@ namespace test values1.sort(); values2.sort(); BOOST_TEST(values1.size() == values2.size() && - std::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent)); + test::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent)); } template diff --git a/test/unordered/Jamfile.v2 b/test/unordered/Jamfile.v2 index 882ec132..5cae0605 100644 --- a/test/unordered/Jamfile.v2 +++ b/test/unordered/Jamfile.v2 @@ -9,9 +9,13 @@ project unordered-test/unordered : requirements all intel:on - intel:-strict-ansi - msvc:/W4 - gcc:"-Wsign-promo -Wunused-parameter -pedantic" + gcc:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter" + darwin:"-pedantic -Wstrict-aliasing -fstrict-aliasing -Wextra -Wsign-promo -Wunused-parameter" + gcc:_GLIBCXX_DEBUG + darwin:_GLIBCXX_DEBUG + msvc:on + gcc:on + darwin:on ; test-suite unordered diff --git a/test/unordered/equality_tests.cpp b/test/unordered/equality_tests.cpp index bfc78f1b..73633a06 100644 --- a/test/unordered/equality_tests.cpp +++ b/test/unordered/equality_tests.cpp @@ -29,36 +29,36 @@ namespace equality_tests }; #define UNORDERED_EQUALITY_SET_TEST(seq1, op, seq2) \ - do { \ + { \ boost::unordered_set set1, set2; \ BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set1, seq1) \ BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set2, seq2) \ BOOST_TEST(set1 op set2); \ - } while(false) + } #define UNORDERED_EQUALITY_MULTISET_TEST(seq1, op, seq2) \ - do { \ + { \ boost::unordered_multiset set1, set2; \ BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set1, seq1) \ BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set2, seq2) \ BOOST_TEST(set1 op set2); \ - } while(false) + } #define UNORDERED_EQUALITY_MAP_TEST(seq1, op, seq2) \ - do { \ + { \ boost::unordered_map map1, map2; \ BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map1, seq1) \ BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map2, seq2) \ BOOST_TEST(map1 op map2); \ - } while(false) + } #define UNORDERED_EQUALITY_MULTIMAP_TEST(seq1, op, seq2) \ - do { \ + { \ boost::unordered_multimap map1, map2; \ BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map1, seq1) \ BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map2, seq2) \ BOOST_TEST(map1 op map2); \ - } while(false) + } #define UNORDERED_SET_INSERT(r, set, item) set.insert(item); #define UNORDERED_MAP_INSERT(r, map, item) \ @@ -89,57 +89,57 @@ namespace equality_tests UNORDERED_AUTO_TEST(equality_key_value_tests) { - UNORDERED_EQUALITY_MULTISET_TEST((1), !=, (2)); - UNORDERED_EQUALITY_SET_TEST((2), ==, (2)); - UNORDERED_EQUALITY_MAP_TEST(((1)(1))((2)(1)), !=, ((1)(1))((3)(1))); + UNORDERED_EQUALITY_MULTISET_TEST((1), !=, (2)) + UNORDERED_EQUALITY_SET_TEST((2), ==, (2)) + UNORDERED_EQUALITY_MAP_TEST(((1)(1))((2)(1)), !=, ((1)(1))((3)(1))) } UNORDERED_AUTO_TEST(equality_collision_test) { UNORDERED_EQUALITY_MULTISET_TEST( - (1), !=, (501)); + (1), !=, (501)) UNORDERED_EQUALITY_MULTISET_TEST( - (1)(251), !=, (1)(501)); + (1)(251), !=, (1)(501)) UNORDERED_EQUALITY_MULTIMAP_TEST( - ((251)(1))((1)(1)), !=, ((501)(1))((1)(1))); + ((251)(1))((1)(1)), !=, ((501)(1))((1)(1))) UNORDERED_EQUALITY_MULTISET_TEST( - (1)(501), ==, (1)(501)); + (1)(501), ==, (1)(501)) UNORDERED_EQUALITY_SET_TEST( - (1)(501), ==, (501)(1)); + (1)(501), ==, (501)(1)) } UNORDERED_AUTO_TEST(equality_group_size_test) { UNORDERED_EQUALITY_MULTISET_TEST( - (10)(20)(20), !=, (10)(10)(20)); + (10)(20)(20), !=, (10)(10)(20)) UNORDERED_EQUALITY_MULTIMAP_TEST( ((10)(1))((20)(1))((20)(1)), !=, - ((10)(1))((20)(1))((10)(1))); + ((10)(1))((20)(1))((10)(1))) UNORDERED_EQUALITY_MULTIMAP_TEST( ((20)(1))((10)(1))((10)(1)), ==, - ((10)(1))((20)(1))((10)(1))); + ((10)(1))((20)(1))((10)(1))) } UNORDERED_AUTO_TEST(equality_map_value_test) { UNORDERED_EQUALITY_MAP_TEST( - ((1)(1)), !=, ((1)(2))); + ((1)(1)), !=, ((1)(2))) UNORDERED_EQUALITY_MAP_TEST( - ((1)(1)), ==, ((1)(1))); + ((1)(1)), ==, ((1)(1))) UNORDERED_EQUALITY_MULTIMAP_TEST( - ((1)(1)), !=, ((1)(2))); + ((1)(1)), !=, ((1)(2))) UNORDERED_EQUALITY_MULTIMAP_TEST( - ((1)(1))((1)(1)), !=, ((1)(1))((1)(2))); + ((1)(1))((1)(1)), !=, ((1)(1))((1)(2))) UNORDERED_EQUALITY_MULTIMAP_TEST( - ((1)(2))((1)(1)), !=, ((1)(1))((1)(2))); + ((1)(2))((1)(1)), !=, ((1)(1))((1)(2))) } UNORDERED_AUTO_TEST(equality_predicate_test) { UNORDERED_EQUALITY_SET_TEST( - (1), ==, (1001)); + (1), ==, (1001)) UNORDERED_EQUALITY_MAP_TEST( - ((1)(2))((1001)(1)), ==, ((1001)(2))((1)(1))); + ((1)(2))((1001)(1)), ==, ((1001)(2))((1)(1))) } // Test that equality still works when the two containers have diff --git a/test/unordered/erase_tests.cpp b/test/unordered/erase_tests.cpp index 74fc6d1f..36ce40a2 100644 --- a/test/unordered/erase_tests.cpp +++ b/test/unordered/erase_tests.cpp @@ -65,7 +65,7 @@ void erase_tests1(Container*, test::random_generator generator = test::default_g while(size > 0 && !x.empty()) { using namespace std; - int index = rand() % x.size(); + int index = rand() % (int) x.size(); BOOST_DEDUCED_TYPENAME Container::const_iterator prev, pos, next; if(index == 0) { prev = pos = x.begin();