diff --git a/example/features/ifdef.cpp b/example/features/ifdef.cpp index 6cf52e0..1736f32 100644 --- a/example/features/ifdef.cpp +++ b/example/features/ifdef.cpp @@ -125,7 +125,7 @@ public: boost::contract::guard c = boost::contract::constructor(this) #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS .postcondition([&] { - BOOST_CONTRACT_ASSERT(size() == (to - from + 1)); + BOOST_CONTRACT_ASSERT(int(size()) == (to - from + 1)); }) #endif ; diff --git a/example/n1962/vector.cpp b/example/n1962/vector.cpp index 52ef7cb..c27aa85 100644 --- a/example/n1962/vector.cpp +++ b/example/n1962/vector.cpp @@ -658,7 +658,9 @@ int main() { vector z(y); typename vector::iterator j = y.begin(); + assert(j != y.end()); typename vector::const_iterator cj = cy.begin(); + assert(cj != cy.end()); y.insert(j, 2, x()); y.push_back(x()); diff --git a/include/boost/contract.hpp b/include/boost/contract.hpp index 4524ced..b56ca51 100644 --- a/include/boost/contract.hpp +++ b/include/boost/contract.hpp @@ -37,9 +37,9 @@ never be used directly by programmers. #include #include -// TODO: Review all warnings for examples, tests, and also lib compilation... - // TODO: Add all copyright and licencing info (to all files, etc.). +// TODO: Document that the correct way of programming contracts for overridden protected and overriding public functions is as follows: Both must use virtual_ (otherwise C++ won't override because mismatching parameters), but overridden protected does not use public_function. See test/public_function/protected.cpp. + #endif // #include guard diff --git a/include/boost/contract/core/exception.hpp b/include/boost/contract/core/exception.hpp index ec43544..6e85d35 100644 --- a/include/boost/contract/core/exception.hpp +++ b/include/boost/contract/core/exception.hpp @@ -48,6 +48,12 @@ public: virtual ~exception() /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */; }; +#ifdef BOOST_MSVC + #pragma warning(push) + #pragma warning(disable: 4275) // Bases w/o DLL spec (bad_cast, etc). + #pragma warning(disable: 4251) // Members w/o DLL spec (string for what_). +#endif + /** Exception thrown when inconsistent return values are passed to overridden virtual public functions. @@ -181,6 +187,10 @@ private: /** @endcond */ }; +#ifdef BOOST_MSVC + #pragma warning(pop) +#endif + /** Represent the operation where the contract assertion failed. This is passed as a parameter to the assertion failure handler functions. diff --git a/include/boost/contract/detail/check_guard.hpp b/include/boost/contract/detail/check_guard.hpp index 9b40c2c..489326a 100644 --- a/include/boost/contract/detail/check_guard.hpp +++ b/include/boost/contract/detail/check_guard.hpp @@ -15,6 +15,11 @@ namespace boost { namespace contract { namespace detail { +#ifdef BOOST_MSVC + #pragma warning(push) + #pragma warning(disable: 4251) // Member w/o DLL spec (mutex_ type). +#endif + class BOOST_CONTRACT_DETAIL_DECLSPEC check_guard : private boost::noncopyable // Non-copyable resource (might use mutex, etc.). { @@ -31,6 +36,10 @@ private: #endif }; +#ifdef BOOST_MSVC + #pragma warning(pop) +#endif + } } } // namespace /** @cond Needed because this header included by other public headers. */ diff --git a/include/boost/contract/detail/inlined/core/exception.hpp b/include/boost/contract/detail/inlined/core/exception.hpp index 1969bb7..c123fc3 100644 --- a/include/boost/contract/detail/inlined/core/exception.hpp +++ b/include/boost/contract/detail/inlined/core/exception.hpp @@ -46,7 +46,7 @@ namespace boost { namespace contract { -exception::~exception() {} +exception::~exception() BOOST_NOEXCEPT_OR_NOTHROW {} bad_virtual_result_cast::bad_virtual_result_cast(char const* from_type_name, char const* to_type_name) { @@ -59,7 +59,7 @@ bad_virtual_result_cast::bad_virtual_result_cast(char const* from_type_name, what_ = text.str(); } -bad_virtual_result_cast::~bad_virtual_result_cast() {} +bad_virtual_result_cast::~bad_virtual_result_cast() BOOST_NOEXCEPT_OR_NOTHROW {} char const* bad_virtual_result_cast::what() const BOOST_NOEXCEPT_OR_NOTHROW { return what_.c_str(); @@ -74,7 +74,7 @@ assertion_failure::assertion_failure(char const* const code) : file_(""), line_(0), code_(code) { init(); } -assertion_failure::~assertion_failure() {} +assertion_failure::~assertion_failure() BOOST_NOEXCEPT_OR_NOTHROW {} char const* assertion_failure::what() const BOOST_NOEXCEPT_OR_NOTHROW { return what_.c_str(); diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 117d09f..8249dd6 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -260,11 +260,6 @@ test-suite specify [ subdir-compile-fail specify : post_pre_error ] ; -test-suite misc -: - [ subdir-run-with-no misc : mutex ] -; - test-suite call_if : [ subdir-run call_if : true_ ] diff --git a/test/call_if/check_if.cpp b/test/call_if/check_if.cpp index 27f4736..9420265 100644 --- a/test/call_if/check_if.cpp +++ b/test/call_if/check_if.cpp @@ -18,11 +18,12 @@ void push_back(std::vector& vect, T const& val) { boost::contract::guard c = boost::contract::function() .postcondition([&] { BOOST_CONTRACT_ASSERT( - boost::contract::call_if >( + boost::contract::check_if >( boost::bind(std::equal_to(), boost::cref(vect.back()), boost::cref(val)) - ).else_([] { ++equal_skips; return true; }) + ) ); + if(!boost::has_equal_to::value) ++equal_skips; }) ; vect.push_back(val); @@ -38,7 +39,7 @@ int main() { std::vector vi; equal_skips = 0; push_back(vi, 123); - BOOST_TEST_EQ(equal_skips, 0); + BOOST_TEST_EQ(equal_skips, 0u); unsigned const cnt = #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS diff --git a/test/constructor/contracts.cpp b/test/constructor/contracts.cpp index e3cb2f5..74503d8 100644 --- a/test/constructor/contracts.cpp +++ b/test/constructor/contracts.cpp @@ -349,77 +349,77 @@ int main() { #endif BOOST_TEST_EQ(a::x_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(a::x_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(a::x_type::ctors(), a::x_type::dtors()); // No leak. BOOST_TEST_EQ(c::y_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(c::y_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(c::y_type::ctors(), c::y_type::dtors()); // No leak. BOOST_TEST_EQ(t<'d'>::z_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'d'>::z_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'d'>::z_type::ctors(), t<'d'>::z_type::dtors()); // No leak. BOOST_TEST_EQ(t<'p'>::z_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'p'>::z_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'p'>::z_type::ctors(), t<'p'>::z_type::dtors()); // No leak. BOOST_TEST_EQ(t<'q'>::z_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'q'>::z_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'q'>::z_type::ctors(), t<'q'>::z_type::dtors()); // No leak. BOOST_TEST_EQ(t<'e'>::z_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::z_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::z_type::ctors(), t<'e'>::z_type::dtors()); // No leak. // Following destroy only copies (actual objects are static data members). BOOST_TEST_EQ(a::n_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(a::n_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(a::n_type::copies(), a::n_type::dtors()); // No leak. BOOST_TEST_EQ(c::m_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(c::m_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(c::m_type::copies(), c::m_type::dtors()); // No leak. BOOST_TEST_EQ(t<'d'>::l_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'d'>::l_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak BOOST_TEST_EQ(t<'p'>::l_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'p'>::l_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak BOOST_TEST_EQ(t<'q'>::l_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'q'>::l_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak BOOST_TEST_EQ(t<'e'>::l_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::l_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak #undef BOOST_CONTRACT_TEST_post diff --git a/test/constructor/decl_entry_static_inv_all.cpp b/test/constructor/decl_entry_static_inv_all.cpp index 6865050..6b46928 100644 --- a/test/constructor/decl_entry_static_inv_all.cpp +++ b/test/constructor/decl_entry_static_inv_all.cpp @@ -12,7 +12,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl diff --git a/test/constructor/decl_entry_static_inv_ends.cpp b/test/constructor/decl_entry_static_inv_ends.cpp index 3c78cff..b919e2a 100644 --- a/test/constructor/decl_entry_static_inv_ends.cpp +++ b/test/constructor/decl_entry_static_inv_ends.cpp @@ -12,7 +12,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl diff --git a/test/constructor/decl_entry_static_inv_mid.cpp b/test/constructor/decl_entry_static_inv_mid.cpp index 5792da8..fe791cd 100644 --- a/test/constructor/decl_entry_static_inv_mid.cpp +++ b/test/constructor/decl_entry_static_inv_mid.cpp @@ -12,7 +12,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl diff --git a/test/constructor/decl_exit_inv_all.cpp b/test/constructor/decl_exit_inv_all.cpp index 8a1405a..92b4f74 100644 --- a/test/constructor/decl_exit_inv_all.cpp +++ b/test/constructor/decl_exit_inv_all.cpp @@ -11,7 +11,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl @@ -76,7 +76,7 @@ std::string ok_a() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "a::ctor::post" << std::endl #endif diff --git a/test/constructor/decl_exit_inv_ends.cpp b/test/constructor/decl_exit_inv_ends.cpp index 655e9b1..2d0b334 100644 --- a/test/constructor/decl_exit_inv_ends.cpp +++ b/test/constructor/decl_exit_inv_ends.cpp @@ -11,7 +11,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl @@ -76,7 +76,7 @@ std::string ok_a() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "a::ctor::post" << std::endl #endif diff --git a/test/constructor/decl_exit_inv_mid.cpp b/test/constructor/decl_exit_inv_mid.cpp index ecabd51..2e3d36f 100644 --- a/test/constructor/decl_exit_inv_mid.cpp +++ b/test/constructor/decl_exit_inv_mid.cpp @@ -11,7 +11,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl @@ -76,7 +76,7 @@ std::string ok_a() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "a::ctor::post" << std::endl #endif diff --git a/test/constructor/decl_exit_static_inv_all.cpp b/test/constructor/decl_exit_static_inv_all.cpp index 8712df0..de618b5 100644 --- a/test/constructor/decl_exit_static_inv_all.cpp +++ b/test/constructor/decl_exit_static_inv_all.cpp @@ -12,7 +12,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl @@ -80,7 +80,7 @@ std::string ok_a() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS << "a::inv" << std::endl #endif diff --git a/test/constructor/decl_exit_static_inv_ends.cpp b/test/constructor/decl_exit_static_inv_ends.cpp index 724a050..6dd67ec 100644 --- a/test/constructor/decl_exit_static_inv_ends.cpp +++ b/test/constructor/decl_exit_static_inv_ends.cpp @@ -12,7 +12,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl @@ -74,7 +74,7 @@ std::string ok_a() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS << "a::inv" << std::endl #endif diff --git a/test/constructor/decl_exit_static_inv_mid.cpp b/test/constructor/decl_exit_static_inv_mid.cpp index 91278bd..6bfafb0 100644 --- a/test/constructor/decl_exit_static_inv_mid.cpp +++ b/test/constructor/decl_exit_static_inv_mid.cpp @@ -12,7 +12,7 @@ #include std::string ok_c() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "a::ctor::pre" << std::endl << "b::ctor::pre" << std::endl @@ -70,7 +70,7 @@ std::string ok_a() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS << "a::inv" << std::endl #endif diff --git a/test/destructor/contracts.cpp b/test/destructor/contracts.cpp index 7b070ea..3480c91 100644 --- a/test/destructor/contracts.cpp +++ b/test/destructor/contracts.cpp @@ -268,39 +268,39 @@ int main() { // Followings destroy only copies (actual objects are static data members). BOOST_TEST_EQ(a::n_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(a::n_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(a::n_type::copies(), a::n_type::dtors()); // No leak. BOOST_TEST_EQ(c::m_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(c::m_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(c::m_type::copies(), c::m_type::dtors()); // No leak. BOOST_TEST_EQ(t<'d'>::l_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'d'>::l_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'d'>::l_type::copies(), t<'d'>::l_type::dtors()); // No leak BOOST_TEST_EQ(t<'p'>::l_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'p'>::l_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'p'>::l_type::copies(), t<'p'>::l_type::dtors()); // No leak BOOST_TEST_EQ(t<'q'>::l_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'q'>::l_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'q'>::l_type::copies(), t<'q'>::l_type::dtors()); // No leak BOOST_TEST_EQ(t<'e'>::l_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::l_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(t<'e'>::l_type::copies(), t<'e'>::l_type::dtors()); // No leak #undef BOOST_CONTRACT_TEST_post diff --git a/test/destructor/decl_entry_inv_all.cpp b/test/destructor/decl_entry_inv_all.cpp index 720c808..1d9998f 100644 --- a/test/destructor/decl_entry_inv_all.cpp +++ b/test/destructor/decl_entry_inv_all.cpp @@ -11,7 +11,7 @@ #include std::string ok_a(bool failed = false) { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "a::static_inv" << std::endl << "a::inv" << std::endl // This can fail. @@ -35,7 +35,7 @@ std::string ok_a(bool failed = false) { enum checked { passed, failed, threw }; std::string ok_b(checked check = passed) { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "b::static_inv" << std::endl << "b::inv" << std::endl // This can fail. @@ -58,7 +58,7 @@ std::string ok_b(checked check = passed) { } std::string ok_c(checked check = passed) { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl // This can fail. diff --git a/test/destructor/decl_entry_inv_ends.cpp b/test/destructor/decl_entry_inv_ends.cpp index cac7c1e..baa28ca 100644 --- a/test/destructor/decl_entry_inv_ends.cpp +++ b/test/destructor/decl_entry_inv_ends.cpp @@ -11,7 +11,7 @@ #include std::string ok_a(bool failed = false) { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "a::static_inv" << std::endl << "a::inv" << std::endl // This can fail. @@ -33,7 +33,7 @@ std::string ok_a(bool failed = false) { } std::string ok_b(bool threw = false) { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "b::static_inv" << std::endl #endif @@ -55,7 +55,7 @@ std::string ok_b(bool threw = false) { enum checked { passed, failed, threw }; std::string ok_c(checked check = passed) { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl // This can fail. diff --git a/test/destructor/decl_entry_inv_mid.cpp b/test/destructor/decl_entry_inv_mid.cpp index ab98d69..25b8aa1 100644 --- a/test/destructor/decl_entry_inv_mid.cpp +++ b/test/destructor/decl_entry_inv_mid.cpp @@ -30,7 +30,7 @@ std::string ok_a() { } std::string ok_b(bool failed = false) { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "b::static_inv" << std::endl << "b::inv" << std::endl // This can fail. @@ -126,7 +126,7 @@ int main() { ok.str(""); ok << ok_a() // Test entry b::inv failed... - << ok_b(BOOST_CONTRACT_TEST_entry_inv) + << ok_b(bool(BOOST_CONTRACT_TEST_entry_inv)) ; out.str(""); } @@ -135,7 +135,7 @@ int main() { } catch(err const&) { #endif ok // ...then exec other dtors and check inv on throw (as dtor threw). - << ok_c(BOOST_CONTRACT_TEST_entry_inv) + << ok_c(bool(BOOST_CONTRACT_TEST_entry_inv)) ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } @@ -173,7 +173,7 @@ int main() { << ok_a() // Test no entry a::inv so no failure here. // Test entry b::inv failed (as all did). - << ok_b(BOOST_CONTRACT_TEST_entry_inv) + << ok_b(bool(BOOST_CONTRACT_TEST_entry_inv)) #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "b::dtor::body" << std::endl #endif diff --git a/test/function/contracts.cpp b/test/function/contracts.cpp index b15e6a7..1531a0d 100644 --- a/test/function/contracts.cpp +++ b/test/function/contracts.cpp @@ -81,15 +81,15 @@ int main() { #endif BOOST_TEST_EQ(x_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(x_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(x_type::ctors(), x_type::dtors()); // No leak. BOOST_TEST_EQ(y_type::copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(y_type::evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(y_type::ctors(), y_type::dtors()); // No leak. #undef BOOST_CONTRACT_TEST_post diff --git a/test/function/decl_pre_all.cpp b/test/function/decl_pre_all.cpp index 1da790a..232b55c 100644 --- a/test/function/decl_pre_all.cpp +++ b/test/function/decl_pre_all.cpp @@ -9,7 +9,7 @@ #include std::string ok_f(bool failed = false) { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "f::pre" << std::endl // Test no failure here. #endif diff --git a/test/function/old_throw.cpp b/test/function/old_throw.cpp index 9d87d7e..cada567 100644 --- a/test/function/old_throw.cpp +++ b/test/function/old_throw.cpp @@ -36,7 +36,7 @@ int main() { BOOST_TEST(false); #endif } catch(err const&) { - ok.str(""); ok + ok.str(""); ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_PRECONDITIONS << "f::pre" << std::endl #endif diff --git a/test/misc/mutex.cpp b/test/misc/mutex.cpp deleted file mode 100644 index 32d8b67..0000000 --- a/test/misc/mutex.cpp +++ /dev/null @@ -1,258 +0,0 @@ - -// Test scoped mutex locks before contracts (no need to also test ctors, etc.). - -#include "../detail/oteststream.hpp" -#include -#include -#include -#include -#include - -boost::contract::test::detail::oteststream out; - -struct b : private boost::contract::constructor_precondition { - static void static_invariant() { out << "b::static_inv" << std::endl; } - void invariant() const { out << "b::inv" << std::endl; } - - b() : boost::contract::constructor_precondition( - [&] { out << "b::ctor::pre" << std::endl; }) { - boost::mutex::scoped_lock lock(mutex_); - boost::contract::guard c = boost::contract::constructor(this) - .old([&] { out << "b::ctor::old" << std::endl; }) - .postcondition([&] { out << "b::ctor::post" << std::endl; }) - ; - out << "b::ctor::body" << std::endl; - } - - virtual ~b() { - boost::mutex::scoped_lock lock(mutex_); - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { out << "b::dtor::old" << std::endl; }) - .postcondition([&] { out << "b::dtor::post" << std::endl; }) - ; - out << "b::dtor::body" << std::endl; - } - - virtual void f(boost::contract::virtual_* v = 0) const { - boost::mutex::scoped_lock lock(mutex_); - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "b::f::pre" << std::endl; }) - .old([&] { out << "b::f::old" << std::endl; }) - .postcondition([&] { out << "b::f::post" << std::endl; }) - ; - out << "b::f::body" << std::endl; - } - - virtual void g(boost::contract::virtual_* v = 0) const { - boost::mutex::scoped_lock lock(mutex_); - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "b::g::pre" << std::endl; }) - .old([&] { out << "b::g::old" << std::endl; }) - .postcondition([&] { out << "b::g::post" << std::endl; }) - ; - out << "b::g::body" << std::endl; - } - -private: - mutable boost::mutex mutex_; -}; - -struct a - #define BASES private boost::contract::constructor_precondition, public b - : BASES -{ - typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; - #undef BASES - - static void static_invariant() { out << "a::static_inv" << std::endl; } - void invariant() const { out << "a::inv" << std::endl; } - - a() : boost::contract::constructor_precondition( - [&] { out << "a::ctor::pre" << std::endl; }) { - boost::mutex::scoped_lock lock(mutex_); - boost::contract::guard c = boost::contract::constructor(this) - .old([&] { out << "a::ctor::old" << std::endl; }) - .postcondition([&] { out << "a::ctor::post" << std::endl; }) - ; - out << "a::ctor::body" << std::endl; - } - - ~a() { - boost::mutex::scoped_lock lock(mutex_); - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { out << "a::dtor::old" << std::endl; }) - .postcondition([&] { out << "a::dtor::post" << std::endl; }) - ; - out << "a::dtor::body" << std::endl; - } - - void f(boost::contract::virtual_* v = 0) const /* override */ { - boost::mutex::scoped_lock lock(mutex_); - boost::contract::guard c = boost::contract::public_function( - v, &a::f, this) - .precondition([&] { out << "a::f::pre" << std::endl; }) - .old([&] { out << "a::f::old" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) - ; - out << "a::f::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(f) - - void g(boost::contract::virtual_* v = 0) const /* override */ { - boost::mutex::scoped_lock lock(mutex_); - boost::contract::guard c = boost::contract::public_function( - v, &a::g, this) - .precondition([&] { out << "a::g::pre" << std::endl; }) - .old([&] { out << "a::g::old" << std::endl; }) - .postcondition([&] { out << "a::g::post" << std::endl; }) - ; - out << "a::g::body" << std::endl; - } - BOOST_CONTRACT_OVERRIDE(g) - -private: - mutable boost::mutex mutex_; -}; - -int main() { - // Unfortunately, I cannot compile Boost.Thread on Cygwin with GCC and - // CLang... I get linker errors even if I use `threadapi=pthread` and add - // `/boost/thread//boost_thread` to the Jamfile. -#ifdef BOOST_MSVC - { - a aa; - boost::thread tf([&aa] { aa.f(); }); - boost::thread tg([&aa] { aa.g(); }); - tf.join(); - tg.join(); - } - - std::ostringstream ok; ok // Mutexes also guarantee order of text in `out`. - // Test constructor. - - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "a::ctor::pre" << std::endl - << "b::ctor::pre" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::old" << std::endl - #endif - << "b::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::ctor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::old" << std::endl - #endif - << "a::ctor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::ctor::post" << std::endl - #endif - - // Test public functions. - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::f::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - << "a::f::old" << std::endl - #endif - << "a::f::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::f::old" << std::endl - << "b::f::post" << std::endl - << "a::f::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_PRECONDITIONS - << "b::g::pre" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::g::old" << std::endl - << "a::g::old" << std::endl - #endif - << "a::g::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::g::old" << std::endl - << "b::g::post" << std::endl - << "a::g::post" << std::endl - #endif - - // Test destructor. - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "a::static_inv" << std::endl - << "a::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::old" << std::endl - #endif - << "a::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "a::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "a::dtor::post" << std::endl - #endif - - #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS - << "b::static_inv" << std::endl - << "b::inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::old" << std::endl - #endif - << "b::dtor::body" << std::endl - #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - << "b::dtor::post" << std::endl - #endif - ; - BOOST_TEST(out.eq(ok.str())); -#endif - return boost::report_errors(); -} - diff --git a/test/old/noncopyable.cpp b/test/old/noncopyable.cpp index 92b520f..6a8a7dc 100644 --- a/test/old/noncopyable.cpp +++ b/test/old/noncopyable.cpp @@ -121,7 +121,7 @@ int main() { old_checks = 0; next(n); - BOOST_TEST_EQ(old_checks, 0); + BOOST_TEST_EQ(old_checks, 0u); // Test virtual functions (old values with `v`). @@ -146,7 +146,7 @@ int main() { a an; old_checks = 0; an.next(n); - BOOST_TEST_EQ(old_checks, 0); + BOOST_TEST_EQ(old_checks, 0u); return boost::report_errors(); } diff --git a/test/public_function/contracts.cpp b/test/public_function/contracts.cpp index 571f216..2e8f33c 100644 --- a/test/public_function/contracts.cpp +++ b/test/public_function/contracts.cpp @@ -70,37 +70,37 @@ int main() { BOOST_TEST_EQ(r.value, "A"); BOOST_TEST_EQ(s.value, "acde"); BOOST_TEST_EQ(s.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 4, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 4u, 0u)); BOOST_TEST_EQ(s.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 4, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 4u, 0u)); BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 for local var. BOOST_TEST_EQ(aa.x.value, "aA"); BOOST_TEST_EQ(aa.x.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.x.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.x.ctors(), aa.x.dtors() + 1); // 1 for member var. BOOST_TEST_EQ(aa.y.value, "cA"); BOOST_TEST_EQ(aa.y.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.y.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.y.ctors(), aa.y.dtors() + 1); // 1 for member var. BOOST_TEST_EQ(aa.t<'d'>::z.value, "dA"); BOOST_TEST_EQ(aa.t<'d'>::z.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.t<'d'>::z.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.t<'d'>::z.ctors(), aa.t<'d'>::z.dtors() + 1); // 1 member. BOOST_TEST_EQ(aa.t<'e'>::z.value, "eA"); BOOST_TEST_EQ(aa.t<'e'>::z.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.t<'e'>::z.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.t<'e'>::z.ctors(), aa.t<'e'>::z.dtors() + 1); // 1 member. #undef BOOST_CONTRACT_TEST_post diff --git a/test/public_function/contracts.hpp b/test/public_function/contracts.hpp index 3df0162..2c40970 100644 --- a/test/public_function/contracts.hpp +++ b/test/public_function/contracts.hpp @@ -151,7 +151,8 @@ struct b { virtual ~b() {} - virtual result_type& f(s_type& s) { // No contract. + // No contract (no virtual_ so this is not actually overridden by a::f). + virtual result_type& f(s_type& s) { static result_type result("none-b"); out << "b::f::body" << std::endl; result.value = s.value; diff --git a/test/public_function/decl_exit_inv_all.cpp b/test/public_function/decl_exit_inv_all.cpp index f19de5a..00cee36 100644 --- a/test/public_function/decl_exit_inv_all.cpp +++ b/test/public_function/decl_exit_inv_all.cpp @@ -35,7 +35,7 @@ std::string ok_begin() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl diff --git a/test/public_function/decl_exit_inv_ends.cpp b/test/public_function/decl_exit_inv_ends.cpp index c293a1f..4982328 100644 --- a/test/public_function/decl_exit_inv_ends.cpp +++ b/test/public_function/decl_exit_inv_ends.cpp @@ -34,7 +34,7 @@ std::string ok_begin() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl diff --git a/test/public_function/decl_exit_inv_mid.cpp b/test/public_function/decl_exit_inv_mid.cpp index fe382da..ecadc28 100644 --- a/test/public_function/decl_exit_inv_mid.cpp +++ b/test/public_function/decl_exit_inv_mid.cpp @@ -33,7 +33,7 @@ std::string ok_begin() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl diff --git a/test/public_function/decl_exit_inv_none.cpp b/test/public_function/decl_exit_inv_none.cpp index 2e8d313..de92935 100644 --- a/test/public_function/decl_exit_inv_none.cpp +++ b/test/public_function/decl_exit_inv_none.cpp @@ -74,6 +74,7 @@ int main() { a_exit_inv = true; b_exit_inv = false; + a_entering_inv = b_entering_inv = c_entering_inv = BOOST_PP_IIF(BOOST_CONTRACT_TEST_entry_inv, true, false); out.str(""); aa.f(); diff --git a/test/public_function/decl_exit_static_inv_all.cpp b/test/public_function/decl_exit_static_inv_all.cpp index b0d2720..1b4df70 100644 --- a/test/public_function/decl_exit_static_inv_all.cpp +++ b/test/public_function/decl_exit_static_inv_all.cpp @@ -35,7 +35,7 @@ std::string ok_begin() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl diff --git a/test/public_function/decl_exit_static_inv_ends.cpp b/test/public_function/decl_exit_static_inv_ends.cpp index 87a0818..7dea82a 100644 --- a/test/public_function/decl_exit_static_inv_ends.cpp +++ b/test/public_function/decl_exit_static_inv_ends.cpp @@ -34,7 +34,7 @@ std::string ok_begin() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl diff --git a/test/public_function/decl_exit_static_inv_mid.cpp b/test/public_function/decl_exit_static_inv_mid.cpp index 822c786..a3326ae 100644 --- a/test/public_function/decl_exit_static_inv_mid.cpp +++ b/test/public_function/decl_exit_static_inv_mid.cpp @@ -33,7 +33,7 @@ std::string ok_begin() { } std::string ok_end() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS << "c::f::old" << std::endl << "c::f::post" << std::endl diff --git a/test/public_function/decl_pre_all.cpp b/test/public_function/decl_pre_all.cpp index 7c878a6..5735833 100644 --- a/test/public_function/decl_pre_all.cpp +++ b/test/public_function/decl_pre_all.cpp @@ -11,7 +11,7 @@ #include std::string ok_begin() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl diff --git a/test/public_function/decl_pre_ends.cpp b/test/public_function/decl_pre_ends.cpp index faf99ef..cfea274 100644 --- a/test/public_function/decl_pre_ends.cpp +++ b/test/public_function/decl_pre_ends.cpp @@ -11,7 +11,7 @@ #include std::string ok_begin() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl diff --git a/test/public_function/decl_pre_mid.cpp b/test/public_function/decl_pre_mid.cpp index aa33279..dfcb6f7 100644 --- a/test/public_function/decl_pre_mid.cpp +++ b/test/public_function/decl_pre_mid.cpp @@ -11,7 +11,7 @@ #include std::string ok_begin() { - std::ostringstream ok; ok + std::ostringstream ok; ok << "" // Suppress a warning. #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl diff --git a/test/public_function/protected.cpp b/test/public_function/protected.cpp index c2ac7b9..54427b5 100644 --- a/test/public_function/protected.cpp +++ b/test/public_function/protected.cpp @@ -11,15 +11,16 @@ boost::contract::test::detail::oteststream out; -// NOTE: This is the correct way of programming contracts for base protected -// and public overriding function. - struct b { static void static_invariant() { out << "b::static_inv" << std::endl; } void invariant() const { out << "b::inv" << std::endl; } protected: - virtual void f() { // Protected do not use public_function (or virtual_). + // NOTE: This is the correct way of programming contracts for overridden + // protected and overriding public functions: Both must use virtual_ + // (otherwise C++ won't override because mismatching parameters), but + // overridden protected does not use public_function. + virtual void f(boost::contract::virtual_* v = 0) { boost::contract::guard c = boost::contract::function() .precondition([] { out << "b::f::pre" << std::endl; }) .old([] { out << "b::f::old" << std::endl; }) diff --git a/test/public_function/virtual.cpp b/test/public_function/virtual.cpp index 10752b9..2915d0e 100644 --- a/test/public_function/virtual.cpp +++ b/test/public_function/virtual.cpp @@ -71,38 +71,38 @@ int main() { BOOST_TEST_EQ(r.value, "A"); BOOST_TEST_EQ(s.value, "acde"); BOOST_TEST_EQ(s.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 4, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 4u, 0u)); BOOST_TEST_EQ(s.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 4, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 4u, 0u)); BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 local var. // Cannot access x via ca, but only via aa. BOOST_TEST_EQ(aa.x.value, "aA"); BOOST_TEST_EQ(aa.x.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.x.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(aa.x.ctors(), aa.x.dtors() + 1); // 1 data member. BOOST_TEST_EQ(ca.y.value, "cA"); BOOST_TEST_EQ(ca.y.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(ca.y.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(ca.y.ctors(), ca.y.dtors() + 1); // 1 data member. BOOST_TEST_EQ(ca.t<'d'>::z.value, "dA"); BOOST_TEST_EQ(ca.t<'d'>::z.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(ca.t<'d'>::z.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(ca.t<'d'>::z.ctors(), ca.t<'d'>::z.dtors() + 1); // 1 member. BOOST_TEST_EQ(ca.t<'e'>::z.value, "eA"); BOOST_TEST_EQ(ca.t<'e'>::z.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(ca.t<'e'>::z.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(ca.t<'e'>::z.ctors(), ca.t<'e'>::z.dtors() + 1); // 1 member. #undef BOOST_CONTRACT_TEST_post diff --git a/test/public_function/virtual_branch.cpp b/test/public_function/virtual_branch.cpp index c41bf4f..e0baa3b 100644 --- a/test/public_function/virtual_branch.cpp +++ b/test/public_function/virtual_branch.cpp @@ -61,30 +61,30 @@ int main() { BOOST_TEST_EQ(r.value, "C"); BOOST_TEST_EQ(s.value, "cde"); BOOST_TEST_EQ(s.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 3, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 3u, 0u)); BOOST_TEST_EQ(s.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 3, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 3u, 0u)); BOOST_TEST_EQ(s.ctors(), s.dtors() + 1); // 1 local var. BOOST_TEST_EQ(cc.y.value, "cC"); BOOST_TEST_EQ(cc.y.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(cc.y.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(cc.y.ctors(), cc.y.dtors() + 1); // 1 data member. BOOST_TEST_EQ(cc.t<'d'>::z.value, "dC"); BOOST_TEST_EQ(cc.t<'d'>::z.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(cc.t<'d'>::z.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(cc.t<'d'>::z.ctors(), cc.t<'d'>::z.dtors() + 1); // 1 member. BOOST_TEST_EQ(cc.t<'e'>::z.value, "eC"); BOOST_TEST_EQ(cc.t<'e'>::z.copies(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(cc.t<'e'>::z.evals(), - BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1, 0)); + BOOST_PP_IIF(BOOST_CONTRACT_TEST_post, 1u, 0u)); BOOST_TEST_EQ(cc.t<'e'>::z.ctors(), cc.t<'e'>::z.dtors() + 1); // 1 member. return boost::report_errors();