From 4bebeb2353f0a000ffd2550c62603febf5f19583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 22 Oct 2020 01:12:59 +0200 Subject: [PATCH] Make sure test suite/examples/bench compile with exceptions disabled (exception-handling=off) --- README.md | 1 + bench/bench_alloc.cpp | 12 +- bench/bench_alloc_expand_bwd.cpp | 8 +- bench/bench_set.hpp | 137 +++++++------ bench/bench_static_vector.cpp | 41 ++-- example/doc_custom_tree.cpp | 6 +- example/doc_custom_vector.cpp | 14 +- test/devector_options_test.cpp | 2 + test/devector_test.cpp | 299 +++++++++++++++++----------- test/global_resource_test.cpp | 15 +- test/memory_resource_logger.hpp | 3 +- test/static_vector_options_test.cpp | 28 ++- test/static_vector_test.cpp | 133 ++++++------- test/static_vector_test.hpp | 16 -- test/test_elem.hpp | 5 + test/vector_options_test.cpp | 2 + 16 files changed, 399 insertions(+), 323 deletions(-) diff --git a/README.md b/README.md index 965820f..cb4fa18 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Distributed under the [Boost Software License, Version 1.0](http://www.boost.org * C++03 * Mostly header-only, library compilation is required for few features. +* Supports compiler modes without exceptions support (e.g. `-fno-exceptions`). ### Build Status diff --git a/bench/bench_alloc.cpp b/bench/bench_alloc.cpp index e17be11..5f1c3ee 100644 --- a/bench/bench_alloc.cpp +++ b/bench/bench_alloc.cpp @@ -13,6 +13,8 @@ #endif #include +#include +#include #define BOOST_INTERPROCESS_VECTOR_ALLOC_STATS @@ -61,7 +63,7 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen dlmalloc_free(first_mem); ++numalloc; - try{ + BOOST_TRY{ dlmalloc_command_ret_t ret; for(size_t e = capacity + 1; e < num_elements; ++e){ size_t received_size; @@ -73,8 +75,7 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen ( m_mode, sizeof(POD) , min, max, &received_size, addr); if(!ret.first){ - std::cout << "(!ret.first)!" << std::endl; - throw int(0); + throw_runtime_error("!ret.first)"); } if(!ret.second){ assert(m_mode == BOOST_CONTAINER_ALLOCATE_NEW); @@ -100,10 +101,11 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen } dlmalloc_free(addr); } - catch(...){ + BOOST_CATCH(...){ dlmalloc_free(addr); - throw; + BOOST_RETHROW; } + BOOST_CATCH_END } assert( dlmalloc_allocated_memory() == 0); diff --git a/bench/bench_alloc_expand_bwd.cpp b/bench/bench_alloc_expand_bwd.cpp index d60cf56..b3249b9 100644 --- a/bench/bench_alloc_expand_bwd.cpp +++ b/bench/bench_alloc_expand_bwd.cpp @@ -13,6 +13,7 @@ #endif #include +#include #define BOOST_CONTAINER_VECTOR_ALLOC_STATS @@ -109,7 +110,7 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements bc::vector v; v.reset_alloc_stats(); void *first_mem = 0; - try{ + BOOST_TRY{ first_mem = bc::dlmalloc_malloc(sizeof(MyInt)*num_elements*3/2); v.push_back(MyInt(0)); bc::dlmalloc_free(first_mem); @@ -121,10 +122,11 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements numexpand += v.num_expand_bwd; capacity = static_cast(v.capacity()); } - catch(...){ + BOOST_CATCH(...){ bc::dlmalloc_free(first_mem); - throw; + BOOST_RETHROW; } + BOOST_CATCH_END } assert(bc::dlmalloc_allocated_memory() == 0); diff --git a/bench/bench_set.hpp b/bench/bench_set.hpp index 300aba4..f4a54bd 100644 --- a/bench/bench_set.hpp +++ b/bench/bench_set.hpp @@ -19,6 +19,7 @@ #include #include #include +#include using boost::timer::cpu_timer; using boost::timer::cpu_times; @@ -394,91 +395,87 @@ template void launch_tests(const char *BoostContName, const char *StdContName) { typedef range_provider get_range_t; - try { - std::cout << "**********************************************" << '\n'; - std::cout << "**********************************************" << '\n'; - std::cout << '\n'; - std::cout << BoostContName << " .VS " << StdContName << '\n'; - std::cout << '\n'; - std::cout << "**********************************************" << '\n'; - std::cout << "**********************************************" << '\n' << std::endl; - { - std::cout << "Copy/Assign/Destroy benchmark:" << BoostContName << std::endl; - cpu_times boost_set_time = copy_destroy_time< BoostClass >(get_range_t::sorted_unique()); - std::cout << "Copy/Assign/Destroy benchmark:" << StdContName << std::endl; - cpu_times std_set_time = copy_destroy_time< StdClass >(get_range_t::sorted_unique()); + std::cout << "**********************************************" << '\n'; + std::cout << "**********************************************" << '\n'; + std::cout << '\n'; + std::cout << BoostContName << " .VS " << StdContName << '\n'; + std::cout << '\n'; + std::cout << "**********************************************" << '\n'; + std::cout << "**********************************************" << '\n' << std::endl; + { + std::cout << "Copy/Assign/Destroy benchmark:" << BoostContName << std::endl; + cpu_times boost_set_time = copy_destroy_time< BoostClass >(get_range_t::sorted_unique()); - std::cout << BoostContName << "/" << StdContName << ": "; - compare_times(boost_set_time, std_set_time); - } - { - std::cout << "Ordered construct benchmark:" << BoostContName << std::endl; - cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)"); + std::cout << "Copy/Assign/Destroy benchmark:" << StdContName << std::endl; + cpu_times std_set_time = copy_destroy_time< StdClass >(get_range_t::sorted_unique()); - std::cout << "Ordered construct benchmark:" << StdContName << std::endl; - cpu_times std_set_time = construct_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");; + std::cout << BoostContName << "/" << StdContName << ": "; + compare_times(boost_set_time, std_set_time); + } + { + std::cout << "Ordered construct benchmark:" << BoostContName << std::endl; + cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)"); - std::cout << BoostContName << "/" << StdContName << ": "; - compare_times(boost_set_time, std_set_time); - } - { - std::cout << "Random construct benchmark:" << BoostContName << std::endl; - cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)"); + std::cout << "Ordered construct benchmark:" << StdContName << std::endl; + cpu_times std_set_time = construct_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)");; - std::cout << "Random construct benchmark:" << StdContName << std::endl; - cpu_times std_set_time = construct_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");; + std::cout << BoostContName << "/" << StdContName << ": "; + compare_times(boost_set_time, std_set_time); + } + { + std::cout << "Random construct benchmark:" << BoostContName << std::endl; + cpu_times boost_set_time = construct_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)"); - std::cout << BoostContName << "/" << StdContName << ": "; - compare_times(boost_set_time, std_set_time); - } - { - std::cout << "Ordered Insert benchmark:" << BoostContName << std::endl; - cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)"); + std::cout << "Random construct benchmark:" << StdContName << std::endl; + cpu_times std_set_time = construct_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)");; - std::cout << "Ordered Insert benchmark:" << StdContName << std::endl; - cpu_times std_set_time = insert_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)"); + std::cout << BoostContName << "/" << StdContName << ": "; + compare_times(boost_set_time, std_set_time); + } + { + std::cout << "Ordered Insert benchmark:" << BoostContName << std::endl; + cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)"); - std::cout << BoostContName << "/" << StdContName << ": "; - compare_times(boost_set_time, std_set_time); - } - { - std::cout << "Random Insert benchmark:" << BoostContName << std::endl; - cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)"); + std::cout << "Ordered Insert benchmark:" << StdContName << std::endl; + cpu_times std_set_time = insert_time< StdClass >(get_range_t::sorted_unique(), get_range_t::sorted(), "(ord)"); - std::cout << "Random Insert benchmark:" << StdContName << std::endl; - cpu_times std_set_time = insert_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)"); + std::cout << BoostContName << "/" << StdContName << ": "; + compare_times(boost_set_time, std_set_time); + } + { + std::cout << "Random Insert benchmark:" << BoostContName << std::endl; + cpu_times boost_set_time = insert_time< BoostClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)"); - std::cout << BoostContName << "/" << StdContName << ": "; - compare_times(boost_set_time, std_set_time); - } - { - std::cout << "Ordered Search benchmark:" << BoostContName << std::endl; - cpu_times boost_set_time = search_time< BoostClass >(get_range_t::sorted_unique(), "(ord)"); + std::cout << "Random Insert benchmark:" << StdContName << std::endl; + cpu_times std_set_time = insert_time< StdClass >(get_range_t::random_unique(), get_range_t::random(), "(rnd)"); - std::cout << "Ordered Search benchmark:" << StdContName << std::endl; - cpu_times std_set_time = search_time< StdClass >(get_range_t::sorted_unique(), "(ord)"); + std::cout << BoostContName << "/" << StdContName << ": "; + compare_times(boost_set_time, std_set_time); + } + { + std::cout << "Ordered Search benchmark:" << BoostContName << std::endl; + cpu_times boost_set_time = search_time< BoostClass >(get_range_t::sorted_unique(), "(ord)"); - std::cout << BoostContName << "/" << StdContName << ": "; - compare_times(boost_set_time, std_set_time); - } - { - std::cout << "Random Search benchmark:" << BoostContName << std::endl; - cpu_times boost_set_time = search_time< BoostClass >(get_range_t::random_unique(), "(rnd)"); + std::cout << "Ordered Search benchmark:" << StdContName << std::endl; + cpu_times std_set_time = search_time< StdClass >(get_range_t::sorted_unique(), "(ord)"); - std::cout << "Random Search benchmark:" << StdContName << std::endl; - cpu_times std_set_time = search_time< StdClass >(get_range_t::random_unique(), "(rnd)"); + std::cout << BoostContName << "/" << StdContName << ": "; + compare_times(boost_set_time, std_set_time); + } + { + std::cout << "Random Search benchmark:" << BoostContName << std::endl; + cpu_times boost_set_time = search_time< BoostClass >(get_range_t::random_unique(), "(rnd)"); - std::cout << BoostContName << "/" << StdContName << ": "; - compare_times(boost_set_time, std_set_time); - } - { - std::cout << "Extensions benchmark:" << BoostContName << std::endl; - extensions_time< BoostClass >(get_range_t::sorted_unique()); - } + std::cout << "Random Search benchmark:" << StdContName << std::endl; + cpu_times std_set_time = search_time< StdClass >(get_range_t::random_unique(), "(rnd)"); - }catch(std::exception &e){ - std::cout << e.what(); + std::cout << BoostContName << "/" << StdContName << ": "; + compare_times(boost_set_time, std_set_time); + } + { + std::cout << "Extensions benchmark:" << BoostContName << std::endl; + extensions_time< BoostClass >(get_range_t::sorted_unique()); } } diff --git a/bench/bench_static_vector.cpp b/bench/bench_static_vector.cpp index d9dd8a7..914e7e4 100644 --- a/bench/bench_static_vector.cpp +++ b/bench/bench_static_vector.cpp @@ -14,8 +14,10 @@ // @brief varray_benchmark.cpp compares the performance of boost::container::varray to boost::container::vector #include "varray.hpp" -#include "boost/container/vector.hpp" -#include "boost/container/static_vector.hpp" +#include +#include +#include + #include "../test/movable_int.hpp" #include #include @@ -114,31 +116,28 @@ void compare_times(cpu_times time_numerator, cpu_times time_denominator){ int main() { - try { - std::cout << "N = " << N << " Iter = " << Iter << "\n\n"; + std::cout << "N = " << N << " Iter = " << Iter << "\n\n"; - std::cout << "varray benchmark:" << std::endl; - cpu_times time_varray = time_it,N > >(); + std::cout << "varray benchmark:" << std::endl; + cpu_times time_varray = time_it,N > >(); - std::cout << "boost::container::static_vector benchmark" << std::endl; - cpu_times time_boost_static_vector = time_it,N > >(); + std::cout << "boost::container::static_vector benchmark" << std::endl; + cpu_times time_boost_static_vector = time_it,N > >(); - std::cout << "boost::container::vector benchmark" << std::endl; - cpu_times time_boost_vector = time_it > >(); + std::cout << "boost::container::vector benchmark" << std::endl; + cpu_times time_boost_vector = time_it > >(); - std::cout << "std::vector benchmark" << std::endl; - cpu_times time_standard_vector = time_it > >(); + std::cout << "std::vector benchmark" << std::endl; + cpu_times time_standard_vector = time_it > >(); - std::cout << "varray/boost::container::vector total time comparison:"; - compare_times(time_varray, time_boost_vector); + std::cout << "varray/boost::container::vector total time comparison:"; + compare_times(time_varray, time_boost_vector); - std::cout << "varray/boost::container::static_vector total time comparison:"; - compare_times(time_varray, time_boost_static_vector); + std::cout << "varray/boost::container::static_vector total time comparison:"; + compare_times(time_varray, time_boost_static_vector); + + std::cout << "varray/std::vector total time comparison:"; + compare_times(time_varray,time_standard_vector); - std::cout << "varray/std::vector total time comparison:"; - compare_times(time_varray,time_standard_vector); - }catch(std::exception &e){ - std::cout << e.what(); - } return 0; } diff --git a/example/doc_custom_tree.cpp b/example/doc_custom_tree.cpp index ad9d9e0..ce10748 100644 --- a/example/doc_custom_tree.cpp +++ b/example/doc_custom_tree.cpp @@ -40,13 +40,13 @@ int main () // //AVLTree based set container - typedef set, std::allocator, AVLTree> AvlSet; + typedef set, new_allocator, AVLTree> AvlSet; //AVLTree based set container without size optimization - typedef set, std::allocator, AVLTreeNoSizeOpt> AvlSetNoSizeOpt; + typedef set, new_allocator, AVLTreeNoSizeOpt> AvlSetNoSizeOpt; //Splay tree based multiset container - typedef multiset, std::allocator, SplayTree> SplayMultiset; + typedef multiset, new_allocator, SplayTree> SplayMultiset; //Use them // diff --git a/example/doc_custom_vector.cpp b/example/doc_custom_vector.cpp index 08dfad7..ba3e473 100644 --- a/example/doc_custom_vector.cpp +++ b/example/doc_custom_vector.cpp @@ -7,9 +7,11 @@ // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// +#include //[doc_custom_vector #include #include +#include //Make sure assertions are active #ifdef NDEBUG @@ -32,8 +34,16 @@ int main () //Requesting capacity for more elements than representable by "unsigned char" //is an error in the size optimized vector. bool exception_thrown = false; - try { size_optimized_vector_t v(256); } - catch(...){ exception_thrown = true; } + /*<-*/ + #ifndef BOOST_NO_EXCEPTIONS + BOOST_TRY{ size_optimized_vector_t v(256); } BOOST_CATCH(...){ exception_thrown = true; } BOOST_CATCH_END + #else + exception_thrown = true; + #endif //BOOST_NO_EXCEPTIONS + /*->*/ + //=try { size_optimized_vector_t v(256); } + //=catch(...){ exception_thrown = true; } + assert(exception_thrown == true); //This option specifies that a vector will increase its capacity 50% diff --git a/test/devector_options_test.cpp b/test/devector_options_test.cpp index 8c8e29f..fad9dc9 100644 --- a/test/devector_options_test.cpp +++ b/test/devector_options_test.cpp @@ -17,6 +17,7 @@ using namespace boost::container; template void test_stored_size_type_impl() { + #ifndef BOOST_NO_EXCEPTIONS DevectorType v; typedef typename DevectorType::size_type size_type; typedef typename DevectorType::value_type value_type; @@ -29,6 +30,7 @@ void test_stored_size_type_impl() BOOST_TEST_THROWS(v.emplace(v.begin(), value_type(1)),std::exception); BOOST_TEST_THROWS(v.reserve(max+1), std::exception); BOOST_TEST_THROWS(DevectorType v2(max+1), std::exception); + #endif } template diff --git a/test/devector_test.cpp b/test/devector_test.cpp index 88ef964..a50c265 100644 --- a/test/devector_test.cpp +++ b/test/devector_test.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include "dummy_test_allocator.hpp" @@ -133,8 +134,6 @@ template void test_constructor_reserve_only_front_back() template void test_constructor_n() { - typedef typename Devector::value_type T; - { Devector a(8); const int expected [] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -148,6 +147,9 @@ template void test_constructor_n() BOOST_TEST(b.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS + typedef typename Devector::value_type T; + BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_default_constructible::value) { test_elem_throw::on_ctor_after(4); @@ -155,15 +157,18 @@ template void test_constructor_n() BOOST_TEST(test_elem_base::no_living_elem()); test_elem_throw::do_not_throw(); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_constructor_n_copy_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; test_elem_throw::on_copy_after(4); const T x(404); BOOST_TEST_THROWS(Devector(8, x), test_exception); test_elem_throw::do_not_throw(); + #endif //#ifndef BOOST_NO_EXCEPTIONS } @@ -220,6 +225,7 @@ template void test_constructor_input_range() BOOST_TEST(test_elem_base::no_living_elem()); /* //if move_if_noexcept is implemented + #ifndef BOOST_NO_EXCEPTIONS if (! boost::move_detail::is_nothrow_copy_constructible::value) { devector input; get_range >(16, input); @@ -233,6 +239,7 @@ template void test_constructor_input_range() } BOOST_TEST(test_elem_base::no_living_elem()); + #endif //#ifndef BOOST_NO_EXCEPTIONS */ } @@ -272,12 +279,14 @@ template void test_constructor_forward_range() BOOST_TEST(b.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible::value) { test_elem_throw::on_copy_after(4); BOOST_TEST_THROWS(Devector c(x.begin(), x.end()), test_exception); test_elem_throw::do_not_throw(); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_constructor_pointer_range() @@ -303,18 +312,18 @@ template void test_constructor_pointer_range() BOOST_TEST(b.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS if (! boost::move_detail::is_nothrow_copy_constructible::value) { test_elem_throw::on_copy_after(4); BOOST_TEST_THROWS(Devector c(xbeg, xend), test_exception); test_elem_throw::do_not_throw(); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_copy_constructor() { - typedef typename Devector::value_type T; - { Devector a; Devector b(a); @@ -331,6 +340,9 @@ template void test_copy_constructor() BOOST_TEST(b.get_alloc_count() <= 1u); } + #ifndef BOOST_NO_EXCEPTIONS + typedef typename Devector::value_type T; + if (! boost::move_detail::is_nothrow_copy_constructible::value) { Devector a; get_range(8, a); @@ -339,6 +351,7 @@ template void test_copy_constructor() BOOST_TEST_THROWS(Devector b(a), test_exception); test_elem_throw::do_not_throw(); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_move_constructor() @@ -385,7 +398,6 @@ template void test_destructor() template void test_assignment() { - typedef typename Devector::value_type T; const typename Devector::size_type alloc_count = boost::container::allocator_traits < typename Devector::allocator_type >::propagate_on_container_copy_assignment::value; @@ -462,6 +474,8 @@ template void test_assignment() BOOST_TEST(a.get_alloc_count() == alloc_count); } + #ifndef BOOST_NO_EXCEPTIONS + typedef typename Devector::value_type T; BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible::value) { // strong guarantee if reallocation is needed (no guarantee otherwise) @@ -475,8 +489,8 @@ template void test_assignment() const int expected[] = {1, 2, 3, 4, 5, 6}; test_equal_range(a, expected); - } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_move_assignment_throwing(dtl::true_) @@ -501,8 +515,6 @@ template void test_move_assignment_throwing(dtl::false_) template void test_move_assignment() { - typedef typename Devector::value_type T; - { // assign to empty (maybe small) Devector a; Devector b; get_range(6, b); @@ -539,6 +551,7 @@ template void test_move_assignment() test_equal_range(b); } + typedef typename Devector::value_type T; test_move_assignment_throwing (boost::move_detail::bool_::value>()); } @@ -546,7 +559,6 @@ template void test_move_assignment() template void test_il_assignment() { #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) - typedef typename Devector::value_type T; { // assign to empty (maybe small) Devector a; @@ -603,6 +615,8 @@ template void test_il_assignment() BOOST_TEST(a.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS + typedef typename Devector::value_type T; if (! boost::move_detail::is_nothrow_copy_constructible::value) { // strong guarantee if reallocation is needed (no guarantee otherwise) @@ -610,130 +624,135 @@ template void test_il_assignment() test_elem_throw::on_copy_after(3); - try + BOOST_TRY { a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; BOOST_TEST(false); - } catch(const test_exception&) {} + } + BOOST_CATCH(const test_exception&) {} + BOOST_CATCH_END test_elem_throw::do_not_throw(); test_equal_range(a, {1, 2, 3, 4, 5, 6}); } + #endif //BOOST_NO_EXCEPTIONS #endif //#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) } template void test_assign_input_range() { - typedef typename Devector::value_type T; + typedef typename Devector::value_type T; - { // assign to empty, keep it small - devector expected; get_range(1, 13, 13, 25, expected); - devector input = expected; + { // assign to empty, keep it small + devector expected; get_range(1, 13, 13, 25, expected); + devector input = expected; - input_iterator input_begin = make_input_iterator(input, input.begin()); - input_iterator input_end = make_input_iterator(input, input.end()); + input_iterator input_begin = make_input_iterator(input, input.begin()); + input_iterator input_end = make_input_iterator(input, input.end()); - Devector a; - a.reset_alloc_stats(); - a.assign(input_begin, input_end); + Devector a; + a.reset_alloc_stats(); + a.assign(input_begin, input_end); - BOOST_TEST(a == expected); - } + BOOST_TEST(a == expected); + } - { // assign to empty (maybe small) - devector input; get_range >(6, input); + { // assign to empty (maybe small) + devector input; get_range >(6, input); - input_iterator input_begin = make_input_iterator(input, input.begin()); - input_iterator input_end = make_input_iterator(input, input.end()); + input_iterator input_begin = make_input_iterator(input, input.begin()); + input_iterator input_end = make_input_iterator(input, input.end()); - Devector a; + Devector a; - a.assign(input_begin, input_end); - const int expected [] = {1, 2, 3, 4, 5, 6}; - test_equal_range(a, expected); - } + a.assign(input_begin, input_end); + const int expected [] = {1, 2, 3, 4, 5, 6}; + test_equal_range(a, expected); + } - { // assign from empty - devector input; get_range >(6, input); - input_iterator input_begin = make_input_iterator(input, input.begin()); + { // assign from empty + devector input; get_range >(6, input); + input_iterator input_begin = make_input_iterator(input, input.begin()); - Devector a; get_range(6, a); - a.assign(input_begin, input_begin); + Devector a; get_range(6, a); + a.assign(input_begin, input_begin); - test_equal_range(a); - } + test_equal_range(a); + } - { // assign to non-empty - devector input; get_range >(6, input); - input_iterator input_begin = make_input_iterator(input, input.begin()); - input_iterator input_end = make_input_iterator(input, input.end()); + { // assign to non-empty + devector input; get_range >(6, input); + input_iterator input_begin = make_input_iterator(input, input.begin()); + input_iterator input_end = make_input_iterator(input, input.end()); - Devector a; get_range(11, 15, 15, 19, a); - a.assign(input_begin, input_end); - const int expected [] = {1, 2, 3, 4, 5, 6}; - test_equal_range(a, expected); - } + Devector a; get_range(11, 15, 15, 19, a); + a.assign(input_begin, input_end); + const int expected [] = {1, 2, 3, 4, 5, 6}; + test_equal_range(a, expected); + } - { // assign to free front - devector input; get_range >(6, input); - input_iterator input_begin = make_input_iterator(input, input.begin()); - input_iterator input_end = make_input_iterator(input, input.end()); + { // assign to free front + devector input; get_range >(6, input); + input_iterator input_begin = make_input_iterator(input, input.begin()); + input_iterator input_end = make_input_iterator(input, input.end()); - Devector a; get_range(11, 15, 15, 19, a); - a.reserve_front(8); - a.reset_alloc_stats(); + Devector a; get_range(11, 15, 15, 19, a); + a.reserve_front(8); + a.reset_alloc_stats(); - a.assign(input_begin, input_end); - const int expected[] = {1, 2, 3, 4, 5, 6}; - test_equal_range(a, expected); - } + a.assign(input_begin, input_end); + const int expected[] = {1, 2, 3, 4, 5, 6}; + test_equal_range(a, expected); + } - { // assignment overlaps contents - devector input; get_range >(6, input); - input_iterator input_begin = make_input_iterator(input, input.begin()); - input_iterator input_end = make_input_iterator(input, input.end()); + { // assignment overlaps contents + devector input; get_range >(6, input); + input_iterator input_begin = make_input_iterator(input, input.begin()); + input_iterator input_end = make_input_iterator(input, input.end()); - Devector a; get_range(11, 15, 15, 19, a); - a.reserve_front(12); - a.reset_alloc_stats(); + Devector a; get_range(11, 15, 15, 19, a); + a.reserve_front(12); + a.reset_alloc_stats(); - a.assign(input_begin, input_end); - const int expected[] = {1, 2, 3, 4, 5, 6}; - test_equal_range(a, expected); - } + a.assign(input_begin, input_end); + const int expected[] = {1, 2, 3, 4, 5, 6}; + test_equal_range(a, expected); + } - { // assignment exceeds contents - devector input; get_range >(12, input); - input_iterator input_begin = make_input_iterator(input, input.begin()); - input_iterator input_end = make_input_iterator(input, input.end()); + { // assignment exceeds contents + devector input; get_range >(12, input); + input_iterator input_begin = make_input_iterator(input, input.begin()); + input_iterator input_end = make_input_iterator(input, input.end()); - Devector a; get_range(11, 13, 13, 15, a); - a.reserve_front(8); - a.reserve_back(8); - a.reset_alloc_stats(); + Devector a; get_range(11, 13, 13, 15, a); + a.reserve_front(8); + a.reserve_back(8); + a.reset_alloc_stats(); - a.assign(input_begin, input_end); - const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; - test_equal_range(a, expected); - } + a.assign(input_begin, input_end); + const int expected[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + test_equal_range(a, expected); + } - if (! boost::move_detail::is_nothrow_copy_constructible::value) - { - // strong guarantee if reallocation is needed (no guarantee otherwise) + #ifndef BOOST_NO_EXCEPTIONS + if (! boost::move_detail::is_nothrow_copy_constructible::value) + { + // strong guarantee if reallocation is needed (no guarantee otherwise) - devector input; get_range >(12, input); - input_iterator input_begin = make_input_iterator(input, input.begin()); - input_iterator input_end = make_input_iterator(input, input.end()); + devector input; get_range >(12, input); + input_iterator input_begin = make_input_iterator(input, input.begin()); + input_iterator input_end = make_input_iterator(input, input.end()); - Devector a; get_range(6, a); + Devector a; get_range(6, a); - test_elem_throw::on_copy_after(3); - BOOST_TEST_THROWS(a.assign(input_begin, input_end), test_exception); - test_elem_throw::do_not_throw(); + test_elem_throw::on_copy_after(3); + BOOST_TEST_THROWS(a.assign(input_begin, input_end), test_exception); + test_elem_throw::do_not_throw(); - const int expected[] = {1, 2, 3, 4, 5, 6}; - test_equal_range(a, expected); - } + const int expected[] = {1, 2, 3, 4, 5, 6}; + test_equal_range(a, expected); + } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_assign_forward_range_throwing(dtl::false_) @@ -829,6 +848,7 @@ template void test_assign_forward_range() BOOST_TEST(a.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS BOOST_IF_CONSTEXPR(! boost::move_detail::is_nothrow_copy_constructible::value) { // strong guarantee if reallocation is needed (no guarantee otherwise) @@ -841,6 +861,7 @@ template void test_assign_forward_range() const int expected [] = {1, 2, 3, 4, 5, 6}; test_equal_range(a, expected); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_assign_pointer_range() @@ -915,6 +936,7 @@ template void test_assign_pointer_range() BOOST_TEST(a.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS if (! boost::move_detail::is_nothrow_copy_constructible::value) { // strong guarantee if reallocation is needed (no guarantee otherwise) @@ -927,6 +949,7 @@ template void test_assign_pointer_range() const int expected[] = {1, 2, 3, 4, 5, 6}; test_equal_range(a, expected); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_assign_n() @@ -996,6 +1019,7 @@ template void test_assign_n() BOOST_TEST(a.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS if (! boost::move_detail::is_nothrow_copy_constructible::value) { // strong guarantee if reallocation is needed (no guarantee otherwise) @@ -1008,12 +1032,12 @@ template void test_assign_n() const int expected[] = {1, 2, 3, 4, 5, 6}; test_equal_range(a, expected); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_assign_il() { #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) - typedef typename Devector::value_type T; { // assign to empty (maybe small) Devector a; @@ -1073,6 +1097,8 @@ template void test_assign_il() BOOST_TEST(a.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS + typedef typename Devector::value_type T; if (! boost::move_detail::is_nothrow_copy_constructible::value) { // strong guarantee if reallocation is needed (no guarantee otherwise) @@ -1084,6 +1110,7 @@ template void test_assign_il() test_equal_range(a, {1, 2, 3, 4, 5, 6}); } + #endif //#ifndef BOOST_NO_EXCEPTIONS #endif //#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) } @@ -1154,10 +1181,12 @@ void test_max_size() void test_exceeding_max_size() {/* - using Devector = gp_devector; + #ifndef BOOST_NO_EXCEPTIONS + using Devector = gp_devector; - Devector a((std::numeric_limits::max)()); - BOOST_TEST_THROWS(a.emplace_back(404), std::length_error); + Devector a((std::numeric_limits::max)()); + BOOST_TEST_THROWS(a.emplace_back(404), std::length_error); + #endif //#ifndef BOOST_NO_EXCEPTIONS */ } @@ -1195,6 +1224,7 @@ template void test_capacity() template void test_resize_front_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::iterator iterator; Devector d; get_range(5, d); @@ -1207,6 +1237,7 @@ template void test_resize_front_throwing(dtl::true_) test_equal_range(d, d_origi); BOOST_TEST(origi_begin == d.begin()); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_resize_front_throwing(dtl::false_) @@ -1277,6 +1308,7 @@ template void test_resize_front() template void test_resize_front_copy_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; typedef typename Devector::iterator iterator; @@ -1305,6 +1337,7 @@ template void test_resize_front_copy_throwing(dtl::true_) test_equal_range(c, c_origi); BOOST_TEST(origi_begin == c.begin()); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_resize_front_copy_throwing(dtl::false_) @@ -1371,6 +1404,7 @@ template void test_resize_front_copy() template void test_resize_back_throwing(dtl::true_) // size < required, constructor throws { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::iterator iterator; Devector d; get_range(5, d); @@ -1383,6 +1417,7 @@ template void test_resize_back_throwing(dtl::true_) test_equal_range(d, d_origi); BOOST_TEST(origi_begin == d.begin()); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_resize_back_throwing(dtl::false_) @@ -1452,6 +1487,7 @@ template void test_resize_back() template void test_resize_back_copy_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; typedef typename Devector::iterator iterator; @@ -1494,6 +1530,7 @@ template void test_resize_back_copy_throwing(dtl::true_) test_equal_range(c, c_origi); BOOST_TEST(origi_begin == c.begin()); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_resize_back_copy_throwing(dtl::false_) @@ -1560,8 +1597,6 @@ template void test_resize_back_copy() /* template void test_constructor_unsafe_uninitialized() { - typedef typename Devector::value_type T; - { Devector a(8, unsafe_uninitialized_tag_t()); BOOST_TEST(a.size() == 8u); @@ -1799,26 +1834,28 @@ template void test_index_operator() template void test_at() { - typedef typename Devector::value_type T; + #ifndef BOOST_NO_EXCEPTIONS + typedef typename Devector::value_type T; - { // non-const at - Devector a; get_range(3, a); + { // non-const at + Devector a; get_range(3, a); - BOOST_TEST(a.at(0) == 1); - a.at(0) = T(100); - BOOST_TEST(a.at(0) == 100); + BOOST_TEST(a.at(0) == 1); + a.at(0) = T(100); + BOOST_TEST(a.at(0) == 100); - BOOST_TEST_THROWS(a.at(3), std::out_of_range); - } + BOOST_TEST_THROWS(a.at(3), std::out_of_range); + } - { // const at - Devector b; get_range(3, b); - const Devector &a = b; + { // const at + Devector b; get_range(3, b); + const Devector &a = b; - BOOST_TEST(a.at(0) == 1); + BOOST_TEST(a.at(0) == 1); - BOOST_TEST_THROWS(a.at(3), std::out_of_range); - } + BOOST_TEST_THROWS(a.at(3), std::out_of_range); + } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_front() @@ -1879,6 +1916,7 @@ void test_data() template void test_emplace_front(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::iterator iterator; Devector b; get_range(4, b); @@ -1892,6 +1930,7 @@ template void test_emplace_front(dtl::true_) BOOST_TEST(origi_begin == new_begin); BOOST_TEST(b.size() == 4u); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_emplace_front(dtl::false_) @@ -1921,7 +1960,6 @@ template void test_emplace_front() template void test_push_front() { typedef typename Devector::value_type T; - typedef typename Devector::iterator iterator; { boost::container::vector expected; get_range >(16, expected); std::reverse(expected.begin(), expected.end()); @@ -1936,6 +1974,8 @@ template void test_push_front() test_equal_range(a, expected); } + #ifndef BOOST_NO_EXCEPTIONS + typedef typename Devector::iterator iterator; if (! boost::move_detail::is_nothrow_copy_constructible::value) { Devector b; get_range(4, b); @@ -1961,10 +2001,12 @@ template void test_push_front() const int expected[] = {2, 1, 2, 3, 4}; test_equal_range(c, expected); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_push_front_rvalue_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; typedef typename Devector::iterator iterator; @@ -1979,6 +2021,7 @@ template void test_push_front_rvalue_throwing(dtl::true_) BOOST_TEST(origi_begin == new_begin); BOOST_TEST(b.size() == 4u); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_push_front_rvalue_throwing(dtl::false_) @@ -2038,6 +2081,7 @@ template void test_pop_front() template void test_emplace_back_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::iterator iterator; Devector b; get_range(4, b); @@ -2051,6 +2095,7 @@ template void test_emplace_back_throwing(dtl::true_) BOOST_TEST(origi_begin == new_begin); BOOST_TEST(b.size() == 4u); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_emplace_back_throwing(dtl::false_) @@ -2078,6 +2123,7 @@ template void test_emplace_back() template void test_push_back_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; typedef typename Devector::iterator iterator; @@ -2094,6 +2140,7 @@ template void test_push_back_throwing(dtl::true_) BOOST_TEST(origi_begin == new_begin); BOOST_TEST(b.size() == 4u); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_push_back_throwing(dtl::false_) @@ -2129,6 +2176,7 @@ template void test_push_back() template void test_push_back_rvalue_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; typedef typename Devector::iterator iterator; @@ -2143,6 +2191,7 @@ template void test_push_back_rvalue_throwing(dtl::true_) BOOST_TEST(origi_begin == new_begin); BOOST_TEST(b.size() == 4u); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_push_back_rvalue_throwing(dtl::false_) @@ -2189,6 +2238,7 @@ template void test_unsafe_push_front() test_equal_range(a, expected); } + #ifndef BOOST_NO_EXCEPTIONS if (! boost::move_detail::is_nothrow_copy_constructible::value) { Devector b; get_range(4, b); @@ -2206,6 +2256,7 @@ template void test_unsafe_push_front() BOOST_TEST(origi_begin == new_begin); BOOST_TEST(b.size() == 4u); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_unsafe_push_front_rvalue() @@ -2248,6 +2299,7 @@ template void test_unsafe_push_back() test_equal_range(a, expected); } + #ifndef BOOST_NO_EXCEPTIONS if (! boost::move_detail::is_nothrow_copy_constructible::value) { Devector b; get_range(4, b); @@ -2265,6 +2317,7 @@ template void test_unsafe_push_back() BOOST_TEST(origi_begin == new_begin); BOOST_TEST(b.size() == 4u); } + #endif } template void test_unsafe_push_back_rvalue() @@ -2320,6 +2373,7 @@ template void test_pop_back() template void test_emplace_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::iterator iterator; Devector j; get_range(4, j); @@ -2332,6 +2386,7 @@ template void test_emplace_throwing(dtl::true_) const int expected[] = {1, 2, 3, 4}; test_equal_range(j, expected); BOOST_TEST(origi_begin == j.begin()); + #endif } template void test_emplace_throwing(dtl::false_) @@ -2340,7 +2395,6 @@ template void test_emplace_throwing(dtl::false_) template void test_emplace() { - typedef typename Devector::value_type T; typedef typename Devector::iterator iterator; { @@ -2433,12 +2487,14 @@ template void test_emplace() test_equal_range(i, expected); } + typedef typename Devector::value_type T; test_emplace_throwing (dtl::bool_::value>()); } template void test_insert_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; typedef typename Devector::iterator iterator; @@ -2454,6 +2510,7 @@ template void test_insert_throwing(dtl::true_) const int expected[] = {1, 2, 3, 4}; test_equal_range(j, expected); BOOST_TEST(origi_begin == j.begin()); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_insert_throwing(dtl::false_) @@ -2581,6 +2638,7 @@ template void test_insert() template void test_insert_rvalue_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; typedef typename Devector::iterator iterator; @@ -2594,6 +2652,7 @@ template void test_insert_rvalue_throwing(dtl::true_) const int expected[] = {1, 2, 3, 4}; test_equal_range(j, expected); BOOST_TEST(origi_begin == j.begin()); + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_insert_rvalue_throwing(dtl::false_) @@ -2701,6 +2760,7 @@ template void test_insert_rvalue() template void test_insert_n_throwing(dtl::true_) { + #ifndef BOOST_NO_EXCEPTIONS typedef typename Devector::value_type T; // insert at begin { @@ -2723,6 +2783,7 @@ template void test_insert_n_throwing(dtl::true_) BOOST_TEST_THROWS(k.insert(k.end(), 4, x), test_exception); test_elem_throw::do_not_throw(); } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_insert_n_throwing(dtl::false_) @@ -3049,6 +3110,7 @@ template void test_insert_input_range() test_equal_range(h, expected); } + #ifndef BOOST_NO_EXCEPTIONS if (! boost::move_detail::is_nothrow_copy_constructible::value) { // insert at begin @@ -3079,6 +3141,7 @@ template void test_insert_input_range() test_elem_throw::do_not_throw(); } } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_insert_range() @@ -3221,6 +3284,7 @@ template void test_insert_range() BOOST_TEST(h.get_alloc_count() == 0u); } + #ifndef BOOST_NO_EXCEPTIONS if (! boost::move_detail::is_nothrow_copy_constructible::value) { // insert at begin @@ -3241,6 +3305,7 @@ template void test_insert_range() test_elem_throw::do_not_throw(); } } + #endif //#ifndef BOOST_NO_EXCEPTIONS } template void test_insert_init_list() @@ -3342,6 +3407,7 @@ template void test_insert_init_list() BOOST_TEST(ret == g.begin() + 2); } + #ifndef BOOST_NO_EXCEPTIONS BOOST_IF_CONSTEXPR (! boost::move_detail::is_nothrow_copy_constructible::value) { // insert at begin @@ -3361,6 +3427,7 @@ template void test_insert_init_list() test_elem_throw::do_not_throw(); } } + #endif //#ifndef BOOST_NO_EXCEPTIONS #endif // #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) } diff --git a/test/global_resource_test.cpp b/test/global_resource_test.cpp index bb6e968..1b2e740 100644 --- a/test/global_resource_test.cpp +++ b/test/global_resource_test.cpp @@ -86,20 +86,23 @@ void test_null_memory_resource() { //Make sure it throw or returns null memory_resource *mr = null_memory_resource(); + BOOST_TEST(mr != 0); + #if !defined(BOOST_NO_EXCEPTIONS) bool bad_allocexception_thrown = false; - try{ + + BOOST_TRY{ mr->allocate(1, 1); } - catch(std::bad_alloc&) { + BOOST_CATCH(std::bad_alloc&) { bad_allocexception_thrown = true; } - catch(...) { + BOOST_CATCH(...) { } + BOOST_CATCH_END + BOOST_TEST(bad_allocexception_thrown == true); - #else - BOOST_TEST(0 == mr->allocate(1, 1)); - #endif + #endif //BOOST_NO_EXCEPTIONS } void test_default_resource() diff --git a/test/memory_resource_logger.hpp b/test/memory_resource_logger.hpp index e8bc405..7649a80 100644 --- a/test/memory_resource_logger.hpp +++ b/test/memory_resource_logger.hpp @@ -13,6 +13,7 @@ #include #include +#include #include class memory_resource_logger @@ -41,7 +42,7 @@ class memory_resource_logger { char *addr =(char*)std::malloc(bytes); if(!addr){ - throw std::bad_alloc(); + boost::container::throw_bad_alloc(); } allocation_info info; info.address = addr; diff --git a/test/static_vector_options_test.cpp b/test/static_vector_options_test.cpp index e8965d5..80e8843 100644 --- a/test/static_vector_options_test.cpp +++ b/test/static_vector_options_test.cpp @@ -10,8 +10,10 @@ #define BOOST_ENABLE_ASSERT_HANDLER #include #include +#include #include //for bad_alloc #include +#include using namespace boost::container; //User-defined assertion to test throw_on_overflow @@ -21,12 +23,20 @@ struct throw_on_overflow_off namespace boost { void assertion_failed(char const *, char const *, char const *, long) { + #ifdef BOOST_NO_EXCEPTIONS + std::abort(); + #else throw throw_on_overflow_off(); + #endif } void assertion_failed_msg(char const *, char const *, char const *, char const *, long ) { + #ifdef BOOST_NO_EXCEPTIONS + std::abort(); + #else throw throw_on_overflow_off(); + #endif } } @@ -76,15 +86,18 @@ void test_throw_on_overflow() v.resize(Capacity); bool expected_type_thrown = false; - try{ + + BOOST_TRY{ v.push_back(0); } - catch(std::bad_alloc&) + BOOST_CATCH(std::bad_alloc&) { expected_type_thrown = true; } - catch(...) + BOOST_CATCH(...) {} + BOOST_CATCH_END + BOOST_TEST(expected_type_thrown == true); BOOST_TEST(v.capacity() == Capacity); } @@ -101,15 +114,18 @@ void test_throw_on_overflow() v.resize(Capacity); bool expected_type_thrown = false; - try{ + + BOOST_TRY{ v.push_back(0); } - catch(throw_on_overflow_off) + BOOST_CATCH(throw_on_overflow_off) { expected_type_thrown = true; } - catch(...) + BOOST_CATCH(...) {} + BOOST_CATCH_END + BOOST_TEST(expected_type_thrown == true); BOOST_TEST(v.capacity() == Capacity); } diff --git a/test/static_vector_test.cpp b/test/static_vector_test.cpp index fcc5358..f092635 100644 --- a/test/static_vector_test.cpp +++ b/test/static_vector_test.cpp @@ -75,12 +75,12 @@ void test_support_for_initializer_list() { #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) { - static_vector sv = {10, 8}; + typedef static_vector sv_cap_2; + sv_cap_2 sv = {10, 8}; BOOST_TEST(10 == sv[0]); BOOST_TEST(8 == sv[1]); - typedef static_vector sv_cap_1; - BOOST_TEST_THROWS(sv_cap_1({1, 1}), std::bad_alloc); + BOOST_TEST_THROWS(sv_cap_2({1, 1, 1}), std::bad_alloc); } { @@ -160,15 +160,15 @@ void test_push_back_nd() for ( size_t i = 0 ; i < N ; ++i ) { - T t(i); + T t(static_cast(i)); s.push_back(t); BOOST_TEST(s.size() == i + 1); BOOST_TEST_THROWS( s.at(i + 1), std::out_of_range ); - BOOST_TEST(T(i) == s.at(i)); - BOOST_TEST(T(i) == s[i]); - BOOST_TEST(T(i) == s.back()); + BOOST_TEST(T((int)i) == s.at(i)); + BOOST_TEST(T((int)i) == s[i]); + BOOST_TEST(T((int)i) == s.back()); BOOST_TEST(T(0) == s.front()); - BOOST_TEST(T(i) == *(s.data() + i)); + BOOST_TEST(T((int)i) == *(s.data() + i)); } } @@ -179,7 +179,7 @@ void test_pop_back_nd() for ( size_t i = 0 ; i < N ; ++i ) { - T t(i); + T t((int)i); s.push_back(t); } @@ -188,9 +188,9 @@ void test_pop_back_nd() s.pop_back(); BOOST_TEST(s.size() == i - 1); BOOST_TEST_THROWS( s.at(i - 1), std::out_of_range ); - BOOST_TEST(T(i - 2) == s.at(i - 2)); - BOOST_TEST(T(i - 2) == s[i - 2]); - BOOST_TEST(T(i - 2) == s.back()); + BOOST_TEST(T((int)i - 2) == s.at(i - 2)); + BOOST_TEST(T((int)i - 2) == s[i - 2]); + BOOST_TEST(T((int)i - 2) == s.back()); BOOST_TEST(T(0) == s.front()); } } @@ -229,7 +229,7 @@ void test_copy_and_assign_nd(T const& val) for ( size_t i = 0 ; i < N ; ++i ) { - T t(i); + T t((int)i); s.push_back(t); v.push_back(t); l.push_back(t); @@ -272,8 +272,8 @@ void test_iterators_nd() for ( size_t i = 0 ; i < N ; ++i ) { - s.push_back(T(i)); - v.push_back(T(i)); + s.push_back(T((int)i)); + v.push_back(T((int)i)); } test_compare_ranges(s.begin(), s.end(), v.begin(), v.end()); @@ -292,7 +292,7 @@ void test_erase_nd() typedef typename static_vector::iterator It; for ( size_t i = 0 ; i < N ; ++i ) - s.push_back(T(i)); + s.push_back(T((int)i)); // erase(pos) { @@ -303,9 +303,9 @@ void test_erase_nd() BOOST_TEST(s1.begin() + i == it); BOOST_TEST(s1.size() == N - 1); for ( size_t j = 0 ; j < i ; ++j ) - BOOST_TEST(s1[j] == T(j)); + BOOST_TEST(s1[j] == T((int)j)); for ( size_t j = i+1 ; j < N ; ++j ) - BOOST_TEST(s1[j-1] == T(j)); + BOOST_TEST(s1[j-1] == T((int)j)); } } // erase(first, last) @@ -319,9 +319,9 @@ void test_erase_nd() BOOST_TEST(s1.begin() + i == it); BOOST_TEST(s1.size() == N - removed); for ( size_t j = 0 ; j < i ; ++j ) - BOOST_TEST(s1[j] == T(j)); + BOOST_TEST(s1[j] == T((int)j)); for ( size_t j = i+n ; j < N ; ++j ) - BOOST_TEST(s1[j-n] == T(j)); + BOOST_TEST(s1[j-n] == T((int)j)); } } } @@ -344,11 +344,11 @@ void test_insert(SV const& s, C const& c) BOOST_TEST(s1.begin() + i == it1); BOOST_TEST(s1.size() == h+n); for ( size_t j = 0 ; j < i ; ++j ) - BOOST_TEST(s1[j] == T(j)); + BOOST_TEST(s1[j] == T((int)j)); for ( size_t j = 0 ; j < n ; ++j ) - BOOST_TEST(s1[j+i] == T(100 + j)); + BOOST_TEST(s1[j+i] == T(100 + (int)j)); for ( size_t j = 0 ; j < h-i ; ++j ) - BOOST_TEST(s1[j+i+n] == T(j+i)); + BOOST_TEST(s1[j+i+n] == T((int)j+(int)i)); } } @@ -365,10 +365,10 @@ void test_insert_nd(T const& val) for ( size_t i = 0 ; i < h ; ++i ) { - s.push_back(T(i)); - ss.push_back(T(100 + i)); - v.push_back(T(100 + i)); - l.push_back(T(100 + i)); + s.push_back(T((int)i)); + ss.push_back(T(100 + (int)i)); + v.push_back(T(100 + (int)i)); + l.push_back(T(100 + (int)i)); } // insert(pos, val) @@ -380,10 +380,10 @@ void test_insert_nd(T const& val) BOOST_TEST(s1.begin() + i == it); BOOST_TEST(s1.size() == h+1); for ( size_t j = 0 ; j < i ; ++j ) - BOOST_TEST(s1[j] == T(j)); + BOOST_TEST(s1[j] == T((int)j)); BOOST_TEST(s1[i] == val); for ( size_t j = 0 ; j < h-i ; ++j ) - BOOST_TEST(s1[j+i+1] == T(j+i)); + BOOST_TEST(s1[j+i+1] == T((int)j+(int)i)); } } // insert(pos, n, val) @@ -396,11 +396,11 @@ void test_insert_nd(T const& val) BOOST_TEST(s1.begin() + i == it); BOOST_TEST(s1.size() == h+n); for ( size_t j = 0 ; j < i ; ++j ) - BOOST_TEST(s1[j] == T(j)); + BOOST_TEST(s1[j] == T((int)j)); for ( size_t j = 0 ; j < n ; ++j ) BOOST_TEST(s1[j+i] == val); for ( size_t j = 0 ; j < h-i ; ++j ) - BOOST_TEST(s1[j+i+n] == T(j+i)); + BOOST_TEST(s1[j+i+n] == T((int)j+(int)i)); } } // insert(pos, first, last) @@ -414,7 +414,8 @@ void test_capacity_0_nd() { static_vector v(5u, T(0)); - static_vector s; + typedef static_vector static_vector_0_t; + static_vector_0_t s; BOOST_TEST(s.size() == 0); BOOST_TEST(s.capacity() == 0); BOOST_TEST_THROWS(s.at(0), std::out_of_range); @@ -426,7 +427,6 @@ void test_capacity_0_nd() BOOST_TEST_THROWS(s.assign(v.begin(), v.end()), std::bad_alloc); BOOST_TEST_THROWS(s.assign(5u, T(0)), std::bad_alloc); BOOST_TEST_THROWS(s.assign(5u, T(0)), std::bad_alloc); - typedef static_vector static_vector_0_t; BOOST_TEST_THROWS(static_vector_0_t s2(v.begin(), v.end()), std::bad_alloc); BOOST_TEST_THROWS(static_vector_0_t s1(5u, T(0)), std::bad_alloc); } @@ -435,7 +435,8 @@ template void test_exceptions_nd() { static_vector v(N, T(0)); - static_vector s(N/2, T(0)); + typedef static_vector static_vector_n_half_t; + static_vector_n_half_t s(N/2, T(0)); BOOST_TEST_THROWS(s.resize(N, T(0)), std::bad_alloc); BOOST_TEST_THROWS(s.push_back(T(0)), std::bad_alloc); @@ -444,7 +445,6 @@ void test_exceptions_nd() BOOST_TEST_THROWS(s.insert(s.end(), v.begin(), v.end()), std::bad_alloc); BOOST_TEST_THROWS(s.assign(v.begin(), v.end()), std::bad_alloc); BOOST_TEST_THROWS(s.assign(N, T(0)), std::bad_alloc); - typedef static_vector static_vector_n_half_t; BOOST_TEST_THROWS(static_vector_n_half_t s2(v.begin(), v.end()), std::bad_alloc); BOOST_TEST_THROWS(static_vector_n_half_t s1(N/2+1, T(0)), std::bad_alloc); } @@ -459,16 +459,16 @@ void test_swap_and_move_nd() for (size_t i = 0 ; i < N ; ++i ) { - v1.push_back(T(i)); - v2.push_back(T(i)); - v3.push_back(T(i)); - v4.push_back(T(i)); + v1.push_back(T((int)i)); + v2.push_back(T((int)i)); + v3.push_back(T((int)i)); + v4.push_back(T((int)i)); } for (size_t i = 0 ; i < N/2 ; ++i ) { - s1.push_back(T(100 + i)); - s2.push_back(T(100 + i)); - s4.push_back(T(100 + i)); + s1.push_back(T(100 + (int)i)); + s2.push_back(T(100 + (int)i)); + s4.push_back(T(100 + (int)i)); } s1.swap(v1); @@ -486,15 +486,15 @@ void test_swap_and_move_nd() BOOST_TEST(s4.size() == N); for (size_t i = 0 ; i < N/2 ; ++i ) { - BOOST_TEST(v1[i] == T(100 + i)); - BOOST_TEST(v4[i] == T(100 + i)); + BOOST_TEST(v1[i] == T(100 + (int)i)); + BOOST_TEST(v4[i] == T(100 + (int)i)); } for (size_t i = 0 ; i < N ; ++i ) { - BOOST_TEST(s1[i] == T(i)); - BOOST_TEST(s2[i] == T(i)); - BOOST_TEST(s3[i] == T(i)); - BOOST_TEST(s4[i] == T(i)); + BOOST_TEST(s1[i] == T((int)i)); + BOOST_TEST(s2[i] == T((int)i)); + BOOST_TEST(s3[i] == T((int)i)); + BOOST_TEST(s4[i] == T((int)i)); } } { @@ -503,14 +503,14 @@ void test_swap_and_move_nd() for (size_t i = 0 ; i < N/2 ; ++i ) { - v1.push_back(T(i)); - v2.push_back(T(i)); - v3.push_back(T(i)); + v1.push_back(T((int)i)); + v2.push_back(T((int)i)); + v3.push_back(T((int)i)); } for (size_t i = 0 ; i < N/3 ; ++i ) { - s1.push_back(T(100 + i)); - s2.push_back(T(100 + i)); + s1.push_back(T(100 + (int)i)); + s2.push_back(T(100 + (int)i)); } s1.swap(v1); @@ -528,13 +528,13 @@ void test_swap_and_move_nd() //BOOST_TEST(v3.size() == 0); BOOST_TEST(s4.size() == N/2); for (size_t i = 0 ; i < N/3 ; ++i ) - BOOST_TEST(v1[i] == T(100 + i)); + BOOST_TEST(v1[i] == T(100 + (int)i)); for (size_t i = 0 ; i < N/2 ; ++i ) { - BOOST_TEST(s1[i] == T(i)); - BOOST_TEST(s2[i] == T(i)); - BOOST_TEST(s3[i] == T(i)); - BOOST_TEST(s4[i] == T(i)); + BOOST_TEST(s1[i] == T((int)i)); + BOOST_TEST(s2[i] == T((int)i)); + BOOST_TEST(s3[i] == T((int)i)); + BOOST_TEST(s4[i] == T((int)i)); } } { @@ -574,7 +574,7 @@ void test_emplace_2p() for (int i = 0 ; i < int(N) ; ++i ) v.emplace_back(i, 100 + i); BOOST_TEST(v.size() == N); - BOOST_TEST_THROWS(v.emplace_back(N, 100 + N), std::bad_alloc); + BOOST_TEST_THROWS(v.emplace_back((int)N, 100 + (int)N), std::bad_alloc); BOOST_TEST(v.size() == N); for (int i = 0 ; i < int(N) ; ++i ) BOOST_TEST(v[i] == T(i, 100 + i)); @@ -681,98 +681,84 @@ int main(int, char* []) test_ctor_ndc(); test_ctor_ndc(); BOOST_TEST(counting_value::count() == 0); - test_ctor_ndc(); test_ctor_ndc(); test_ctor_nc(5); test_ctor_nc(5); test_ctor_nc(5); BOOST_TEST(counting_value::count() == 0); - test_ctor_nc(5); test_ctor_nc(5); test_ctor_nd(5, 1); test_ctor_nd(5, value_nd(1)); test_ctor_nd(5, counting_value(1)); BOOST_TEST(counting_value::count() == 0); - test_ctor_nd(5, shptr_value(1)); test_ctor_nd(5, produce_movable_and_copyable_int()); test_resize_nc(5); test_resize_nc(5); test_resize_nc(5); BOOST_TEST(counting_value::count() == 0); - test_resize_nc(5); test_resize_nc(5); test_resize_nd(5, 1); test_resize_nd(5, value_nd(1)); test_resize_nd(5, counting_value(1)); BOOST_TEST(counting_value::count() == 0); - test_resize_nd(5, shptr_value(1)); test_resize_nd(5, produce_movable_and_copyable_int()); test_push_back_nd(); test_push_back_nd(); test_push_back_nd(); BOOST_TEST(counting_value::count() == 0); - test_push_back_nd(); test_push_back_nd(); test_pop_back_nd(); test_pop_back_nd(); test_pop_back_nd(); BOOST_TEST(counting_value::count() == 0); - test_pop_back_nd(); test_pop_back_nd(); test_copy_and_assign_nd(1); test_copy_and_assign_nd(value_nd(1)); test_copy_and_assign_nd(counting_value(1)); BOOST_TEST(counting_value::count() == 0); - test_copy_and_assign_nd(shptr_value(1)); test_copy_and_assign_nd(produce_movable_and_copyable_int()); test_iterators_nd(); test_iterators_nd(); test_iterators_nd(); BOOST_TEST(counting_value::count() == 0); - test_iterators_nd(); test_iterators_nd(); test_erase_nd(); test_erase_nd(); test_erase_nd(); BOOST_TEST(counting_value::count() == 0); - test_erase_nd(); test_erase_nd(); test_insert_nd(50); test_insert_nd(value_nd(50)); test_insert_nd(counting_value(50)); BOOST_TEST(counting_value::count() == 0); - test_insert_nd(shptr_value(50)); test_insert_nd(produce_movable_and_copyable_int()); test_capacity_0_nd(); test_capacity_0_nd(); test_capacity_0_nd(); BOOST_TEST(counting_value::count() == 0); - test_capacity_0_nd(); test_capacity_0_nd(); test_exceptions_nd(); test_exceptions_nd(); test_exceptions_nd(); BOOST_TEST(counting_value::count() == 0); - test_exceptions_nd(); test_exceptions_nd(); test_swap_and_move_nd(); test_swap_and_move_nd(); test_swap_and_move_nd(); BOOST_TEST(counting_value::count() == 0); - test_swap_and_move_nd(); test_swap_and_move_nd(); test_emplace_0p(); @@ -785,7 +771,6 @@ int main(int, char* []) test_sv_elem(value_nd(50)); test_sv_elem(counting_value(50)); BOOST_TEST(counting_value::count() == 0); - test_sv_elem(shptr_value(50)); test_sv_elem(movable_and_copyable_int(50)); BOOST_TEST(default_init_test() == true); diff --git a/test/static_vector_test.hpp b/test/static_vector_test.hpp index f279a01..d53eaf6 100644 --- a/test/static_vector_test.hpp +++ b/test/static_vector_test.hpp @@ -13,8 +13,6 @@ #include -#define BOOST_SP_DISABLE_THREADS -#include #include "movable_int.hpp" using namespace boost::container; @@ -91,18 +89,4 @@ struct has_nothrow_move } -class shptr_value -{ - typedef boost::shared_ptr Ptr; -public: - explicit shptr_value(int a = 0) : m_ptr(new int(a)) {} - shptr_value & operator=(int a) - { m_ptr.reset(new int(a)); return *this; } - - bool operator==(shptr_value const& v) const { return *m_ptr == *(v.m_ptr); } - bool operator<(shptr_value const& v) const { return *m_ptr < *(v.m_ptr); } -private: - boost::shared_ptr m_ptr; -}; - #endif // BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP diff --git a/test/test_elem.hpp b/test/test_elem.hpp index b57a8dd..20cb4a8 100644 --- a/test/test_elem.hpp +++ b/test/test_elem.hpp @@ -13,6 +13,7 @@ #define BOOST_CONTAINER_TEST_TEST_ELEM_HPP #include +#include namespace boost { namespace container { @@ -51,7 +52,11 @@ struct test_elem_throw if (counter == 0) { --counter; + #ifndef BOOST_NO_EXCEPTIONS throw test_exception(); + #else + std::abort(); + #endif } } } diff --git a/test/vector_options_test.cpp b/test/vector_options_test.cpp index 9b414fb..f33cd79 100644 --- a/test/vector_options_test.cpp +++ b/test/vector_options_test.cpp @@ -17,6 +17,7 @@ using namespace boost::container; template void test_stored_size_type_impl() { + #ifndef BOOST_NO_EXCEPTIONS VectorType v; typedef typename VectorType::size_type size_type; typedef typename VectorType::value_type value_type; @@ -29,6 +30,7 @@ void test_stored_size_type_impl() BOOST_TEST_THROWS(v.emplace(v.begin(), value_type(1)),std::exception); BOOST_TEST_THROWS(v.reserve(max+1), std::exception); BOOST_TEST_THROWS(VectorType v2(max+1), std::exception); + #endif } template