From aac3e561986a7f9faea10d19d78827b5bbfc2b5a Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Fri, 5 Jun 2015 08:28:41 -0700 Subject: [PATCH] added a version of check_guard (but without any thread sync yet) --- example/Jamfile.v2 | 2 +- example/meyer97/stack4.hpp | 24 ++-- .../{stack4_run.cpp => stack4_main.cpp} | 0 include/boost/contract.hpp | 2 +- include/boost/contract/aux_/check_guard.hpp | 59 +++++++++ .../contract/aux_/function/constructor.hpp | 9 +- .../contract/aux_/function/destructor.hpp | 3 + .../contract/aux_/function/free_function.hpp | 7 +- .../contract/aux_/function/public_member.hpp | 13 +- .../aux_/function/public_static_member.hpp | 8 +- include/boost/contract/core/config.hpp | 15 +++ include/boost/contract/core/set_nothing.hpp | 12 +- .../contract/core/set_postcondition_only.hpp | 19 ++- .../contract/core/set_precondition_only.hpp | 10 +- .../core/set_precondition_postcondition.hpp | 22 +++- .../boost/contract/{scoped.hpp => guard.hpp} | 17 +-- include/boost/contract/oldof.hpp | 12 +- include/boost/contract/public_member.hpp | 76 +++++------- test/Jamfile.v2 | 4 +- test/constructor/bases.cpp | 8 +- test/constructor/body_throw.cpp | 8 +- test/constructor/no_pre-error.cpp | 4 +- test/destructor/bases.cpp | 8 +- test/destructor/body_throw.cpp | 8 +- test/destructor/no_pre-error.cpp | 4 +- test/disable/checking.cpp | 112 ++++++++++++++++++ test/free_function/body_throw.cpp | 4 +- test/free_function/{nominal.cpp => main.cpp} | 4 +- test/private_member/bases.cpp | 6 +- test/private_member/body_throw.cpp | 4 +- test/protected_member/bases.cpp | 6 +- test/protected_member/body_throw.cpp | 4 +- test/public_member/bases.hpp | 8 +- test/public_member/body_throw.cpp | 8 +- test/public_member/static.cpp | 6 +- test/public_member/static_body_throw.cpp | 4 +- test/set/nothing.cpp | 4 +- test/set/post_only.cpp | 4 +- test/set/post_post-error.cpp | 4 +- test/set/post_pre.cpp | 4 +- test/set/post_pre_post-error.cpp | 4 +- test/set/pre_only.cpp | 4 +- test/set/pre_post.cpp | 4 +- test/set/pre_post_pre-error.cpp | 4 +- test/set/pre_pre-error.cpp | 4 +- 45 files changed, 394 insertions(+), 162 deletions(-) rename example/meyer97/{stack4_run.cpp => stack4_main.cpp} (100%) create mode 100644 include/boost/contract/aux_/check_guard.hpp rename include/boost/contract/{scoped.hpp => guard.hpp} (61%) create mode 100644 test/disable/checking.cpp rename test/free_function/{nominal.cpp => main.cpp} (94%) diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 35942da..829b304 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -1,3 +1,3 @@ -subdir-run meyer97 : stack4_run ; +subdir-run meyer97 : stack4_main ; diff --git a/example/meyer97/stack4.hpp b/example/meyer97/stack4.hpp index 722e45f..ad3a388 100644 --- a/example/meyer97/stack4.hpp +++ b/example/meyer97/stack4.hpp @@ -3,12 +3,14 @@ #define STACK4_HPP_ #include +#include template class stack4 #define BASES private boost::contract::constructor_precondition > : BASES { +public: typedef BOOST_CONTRACT_BASE_TYPES(BASES) base_types; #undef BASES @@ -18,15 +20,15 @@ class stack4 BOOST_CONTRACT_ASSERT(empty() == (count() == 0)); // Empty if no item. } -public: /* Initialization */ // Allocate static from a maximum of n items. - explicit stack4(int n) : - boost::contract::constructor_precondition([&] { - BOOST_CONTRACT_ASSERT(n >= 0); // Non-negative capacity. - }) - { + static void stack4_precondition(int const& n) { + // Its own func. for MSVC 2010 bug with lambdas in template init. list. + BOOST_CONTRACT_ASSERT(n >= 0); // Non-negative capacity. + } + explicit stack4(int n) : boost::contract::constructor_precondition( + boost::bind(&stack4::stack4_precondition, boost::cref(n))) { auto c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(capacity() == n); // Capacity set. @@ -66,7 +68,7 @@ public: delete[] array_; capacity_ = other.capacity_; - count_ = other.capacity_; + count_ = other.count_; array_ = new T[other.capacity_]; for(int i = 0; i < other.count_; ++i) array_[i] = other.array_[i]; return *this; @@ -109,8 +111,8 @@ public: bool result; auto c = boost::contract::public_member(this) .postcondition([&] { - BOOST_CONTRACT_ASSERT(result == - (count() == 0)); // Empty definition. + BOOST_CONTRACT_ASSERT( // Empty definition. + result == (count() == 0)); }) ; return result = (count_ == 0); @@ -121,8 +123,8 @@ public: bool result; auto c = boost::contract::public_member(this) .postcondition([&] { - BOOST_CONTRACT_ASSERT(result == - (count() == capacity())); // Full definition. + BOOST_CONTRACT_ASSERT( // Full definition. + result == (count() == capacity())); }) ; return result = (count_ == capacity_); diff --git a/example/meyer97/stack4_run.cpp b/example/meyer97/stack4_main.cpp similarity index 100% rename from example/meyer97/stack4_run.cpp rename to example/meyer97/stack4_main.cpp diff --git a/include/boost/contract.hpp b/include/boost/contract.hpp index 1d2b94d..a74766d 100644 --- a/include/boost/contract.hpp +++ b/include/boost/contract.hpp @@ -9,12 +9,12 @@ #include #include #include +#include #include #include #include #include #include -#include #endif // #include guard diff --git a/include/boost/contract/aux_/check_guard.hpp b/include/boost/contract/aux_/check_guard.hpp new file mode 100644 index 0000000..7ea9185 --- /dev/null +++ b/include/boost/contract/aux_/check_guard.hpp @@ -0,0 +1,59 @@ + +#ifndef BOOST_CONTRACT_AUX_CHECK_GUARD_HPP_ +#define BOOST_CONTRACT_AUX_CHECK_GUARD_HPP_ + +#include +/** @cond */ +#include +#include +#include +/** @endcond */ + +/* PUBLIC */ + +// NOTE: These macros depend on their caller's code (e.g., has `base_call()`), +// but they are defined here to avoid code duplication at the callers' side. + +#define BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN \ + if(boost::contract::aux::check_guard::checking()) return; \ + boost::contract::aux::check_guard BOOST_CONTRACT_AUX_CHECKING_GUARD_VAR_; + +#define BOOST_CONTRACT_AUX_SUBCONTRACTED_CHECK_GUARD_OR_RETURN \ + boost::shared_ptr \ + BOOST_CONTRACT_AUX_CHECKING_GUARD_VAR_; \ + if(!this->base_call()) { \ + if(boost::contract::aux::check_guard::checking()) return; \ + BOOST_CONTRACT_AUX_CHECKING_GUARD_VAR_ = \ + boost::make_shared(); \ + } + +/* PRIVATE */ + +#define BOOST_CONTRACT_AUX_CHECKING_GUARD_VAR_ \ + BOOST_CONTRACT_AUX_NAME1(BOOST_PP_CAT(checking, __LINE__)) + +/* CODE */ + +namespace boost { namespace contract { namespace aux { + +// TODO: Consider what to do with multi-threads... multi-reads/one-write locks +// via boost::shared_mutex? should each thread have each own contract checking +// bool resource? + +struct check_guard { + explicit check_guard() { checking_ = true; } + ~check_guard() { checking_ = false; } + + static bool checking() { return checking_; } + +private: + static bool checking_; +}; + +// TODO: This state must go into a .cpp with dyn linking (for DLLs). +bool check_guard::checking_ = false; + +} } } // namespace + +#endif // #include guard + diff --git a/include/boost/contract/aux_/function/constructor.hpp b/include/boost/contract/aux_/function/constructor.hpp index 951cb99..90a36a6 100644 --- a/include/boost/contract/aux_/function/constructor.hpp +++ b/include/boost/contract/aux_/function/constructor.hpp @@ -4,6 +4,7 @@ #include #include +#include #include /** @cond */ #include @@ -15,10 +16,9 @@ namespace boost { namespace contract { namespace aux { template class constructor : public check_pre_post_inv { public: - explicit constructor(C* obj) : - check_pre_post_inv( - boost::contract::from_constructor, obj) - { + explicit constructor(C* obj) : check_pre_post_inv( + boost::contract::from_constructor, obj) { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN // No object before ctor body so check only static inv at entry. this->check_entry_static_inv(); } @@ -26,6 +26,7 @@ public: // Ctor pre checked by constructor_precondition at start of init list. ~constructor() { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN // If ctor body threw, no obj so check only static inv. Otherwise, obj // constructed so check static inv, non-static inv, and post. if(std::uncaught_exception()) { diff --git a/include/boost/contract/aux_/function/destructor.hpp b/include/boost/contract/aux_/function/destructor.hpp index 0c2c801..282c9ea 100644 --- a/include/boost/contract/aux_/function/destructor.hpp +++ b/include/boost/contract/aux_/function/destructor.hpp @@ -4,6 +4,7 @@ #include #include +#include #include /** @cond */ #include @@ -19,6 +20,7 @@ public: check_pre_post_inv( boost::contract::from_destructor, obj) { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN // Obj exists (before dtor body) so check static and non-static inv. this->check_entry_inv(); } @@ -26,6 +28,7 @@ public: // Dtor cannot have pre because it has no parameters. ~destructor() { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN // If dtor body threw, obj still exists so check subcontracted static // and non-static inv (but no post because of throw). Otherwise, obj // destructed so check static inv and post (even if there is no obj diff --git a/include/boost/contract/aux_/function/free_function.hpp b/include/boost/contract/aux_/function/free_function.hpp index a91ffa5..23c9d63 100644 --- a/include/boost/contract/aux_/function/free_function.hpp +++ b/include/boost/contract/aux_/function/free_function.hpp @@ -4,6 +4,7 @@ #include #include +#include #include /** @cond */ #include @@ -19,10 +20,14 @@ public: explicit basic_free_function() : check_pre_post(From) {} private: - void pre_available() /* override */ { this->check_pre(); } + void pre_available() /* override */ { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN + this->check_pre(); + } public: ~basic_free_function() { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN if(!std::uncaught_exception()) this->check_post(); } }; diff --git a/include/boost/contract/aux_/function/public_member.hpp b/include/boost/contract/aux_/function/public_member.hpp index 198f5cb..5eba09a 100644 --- a/include/boost/contract/aux_/function/public_member.hpp +++ b/include/boost/contract/aux_/function/public_member.hpp @@ -5,8 +5,8 @@ #include #include #include +#include /** @cond */ -#include #include /** @endcond */ @@ -19,6 +19,7 @@ public: check_subcontracted_pre_post_inv( boost::contract::from_public_member, v, obj, r, a0) { + BOOST_CONTRACT_AUX_SUBCONTRACTED_CHECK_GUARD_OR_RETURN this->copy_subcontracted_oldof(); this->check_subcontracted_entry_inv(); if(this->base_call()) { // Throw no_error so not in dtor. @@ -27,10 +28,13 @@ public: } private: - void pre_available() /* override */ { this->check_subcontracted_pre(); } + void pre_available() /* override */ { + BOOST_CONTRACT_AUX_SUBCONTRACTED_CHECK_GUARD_OR_RETURN + this->check_subcontracted_pre(); + } void post_available() /* override */ { - // Body did not throw. + BOOST_CONTRACT_AUX_SUBCONTRACTED_CHECK_GUARD_OR_RETURN if(this->base_call() && !std::uncaught_exception()) { this->check_subcontracted_post(); // Throw no_error so not in dtor. } @@ -38,13 +42,14 @@ private: public: ~public_member() { + BOOST_CONTRACT_AUX_SUBCONTRACTED_CHECK_GUARD_OR_RETURN if(!this->base_call()) { this->check_subcontracted_exit_inv(); if(!std::uncaught_exception()) this->check_subcontracted_post(); } } }; - + } } } // namespace #endif // #include guard diff --git a/include/boost/contract/aux_/function/public_static_member.hpp b/include/boost/contract/aux_/function/public_static_member.hpp index c0182d0..5704ff2 100644 --- a/include/boost/contract/aux_/function/public_static_member.hpp +++ b/include/boost/contract/aux_/function/public_static_member.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include /** @cond */ #include @@ -19,14 +20,19 @@ class public_static_member : public check_pre_post_inv { public: explicit public_static_member() : check_pre_post_inv( boost::contract::from_public_member, 0) { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN this->check_entry_static_inv(); } private: - void pre_available() /* override */ { this->check_pre(); } + void pre_available() /* override */ { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN + this->check_pre(); + } public: ~public_static_member() { + BOOST_CONTRACT_AUX_CHECK_GUARD_OR_RETURN this->check_exit_static_inv(); if(!std::uncaught_exception()) this->check_post(); } diff --git a/include/boost/contract/core/config.hpp b/include/boost/contract/core/config.hpp index 99620ad..ecef97a 100644 --- a/include/boost/contract/core/config.hpp +++ b/include/boost/contract/core/config.hpp @@ -18,5 +18,20 @@ # define BOOST_CONTRACT_CONFIG_STATIC_INVARIANT static_invariant #endif +// TODO: Implement following up/down error levels. +// #ifdef PEDANTIC +// * error: if contracted class missing `invariant const [volatile]` +// mistakes: inv func could be missing const, be misspelled, not be +// public, etc. +// * error: if `invariant const` but not `invariant const volatile` and +// there are contracts for volatile members. +// mistakes: assume `invariant const` will be called also for volatile +// members. +// * error: if R != result_type& && R != optional>& +// mistakes: c++ should warn already if overriding func has different +// result type (but maybe not if it's a covariant type, in which case +// the lib's cast on v' void* result_ will probably segfault?). +// #ifdef PERMISSIVE + #endif // #include guard diff --git a/include/boost/contract/core/set_nothing.hpp b/include/boost/contract/core/set_nothing.hpp index 9275df3..63a36d1 100644 --- a/include/boost/contract/core/set_nothing.hpp +++ b/include/boost/contract/core/set_nothing.hpp @@ -8,7 +8,7 @@ /** @cond */ #include /** @endcond */ - + namespace boost { namespace contract { // TODO: Make sure all friend declarations are at bottom of public if part of @@ -16,20 +16,22 @@ namespace boost { namespace contract { // TODO: Do I need to store contracts as shared_ptr or unique_ptr is sufficient? -class set_nothing { +class set_nothing { // Copyable as shared * (OK also for RAII). public: // No set function members here. private: typedef boost::shared_ptr check_ptr; + explicit set_nothing(check_ptr check) : check_(check) {} + check_ptr check_; // Friendship used to limit library's public API. - friend class scoped; + friend class guard; friend class set_precondition_only; - - template + + template friend class set_postcondition_only; }; diff --git a/include/boost/contract/core/set_postcondition_only.hpp b/include/boost/contract/core/set_postcondition_only.hpp index 088ef33..9623348 100644 --- a/include/boost/contract/core/set_postcondition_only.hpp +++ b/include/boost/contract/core/set_postcondition_only.hpp @@ -11,10 +11,17 @@ #include /** @endcond */ -namespace boost { namespace contract { +namespace boost { + namespace contract { + template + class set_precondition_postcondition; + } +} +namespace boost { namespace contract { + template -class set_postcondition_only { +class set_postcondition_only { // Copyable as shared * (OK also for RAII). public: template set_nothing postcondition(F const& f) { @@ -25,14 +32,14 @@ public: private: typedef boost::shared_ptr::type> > check_ptr; + explicit set_postcondition_only(check_ptr check) : check_(check) {} + check_ptr check_; // Friendship used to limit library's public API. - friend class scoped; - - template - friend class set_precondition_postcondition; + friend class guard; + friend class set_precondition_postcondition; template friend set_postcondition_only constructor(C*); diff --git a/include/boost/contract/core/set_precondition_only.hpp b/include/boost/contract/core/set_precondition_only.hpp index ff67e87..a36ec52 100644 --- a/include/boost/contract/core/set_precondition_only.hpp +++ b/include/boost/contract/core/set_precondition_only.hpp @@ -11,8 +11,8 @@ /** @endcond */ namespace boost { namespace contract { - -class set_precondition_only { + +class set_precondition_only { // Copyable as shared * (OK also for RAII). public: template set_nothing precondition(F const& f) { @@ -22,12 +22,14 @@ public: private: typedef boost::shared_ptr check_ptr; + explicit set_precondition_only(check_ptr check) : check_(check) {} + check_ptr check_; // Friendship used to limit library's public API. - friend class scoped; - + friend class guard; + template friend class set_precondition_postcondition; }; diff --git a/include/boost/contract/core/set_precondition_postcondition.hpp b/include/boost/contract/core/set_precondition_postcondition.hpp index 5457635..9be5ad2 100644 --- a/include/boost/contract/core/set_precondition_postcondition.hpp +++ b/include/boost/contract/core/set_precondition_postcondition.hpp @@ -23,7 +23,7 @@ namespace boost { namespace boost { namespace contract { template -class set_precondition_postcondition { +class set_precondition_postcondition { // Copyable as shared * (OK for RAII). public: template set_postcondition_only precondition(F const& f) { @@ -40,30 +40,48 @@ public: private: typedef boost::shared_ptr::type> > check_ptr; + explicit set_precondition_postcondition(check_ptr check) : check_(check) {} + check_ptr check_; // Friendship used to limit library's public API. - friend class scoped; + friend class guard; friend set_precondition_postcondition<> free_function(); friend set_precondition_postcondition<> protected_member(); friend set_precondition_postcondition<> private_member(); template friend set_precondition_postcondition<> public_member(); + + template + friend set_precondition_postcondition<> public_member(C*); template friend set_precondition_postcondition<> public_member(virtual_*, C*); template friend set_precondition_postcondition public_member(virtual_*, R_&, C*); + + /* arity = 0 */ template friend set_precondition_postcondition<> public_member(virtual_*, F, C*); + + template + friend set_precondition_postcondition public_member( + virtual_*, R_&, F, C*); + + /* arity = 1 */ + + template + friend set_precondition_postcondition<> public_member( + virtual_*, F, C*, A0&); template friend set_precondition_postcondition public_member( virtual_*, R_&, F, C*, A0&); + // TODO: Support configurable arity. }; diff --git a/include/boost/contract/scoped.hpp b/include/boost/contract/guard.hpp similarity index 61% rename from include/boost/contract/scoped.hpp rename to include/boost/contract/guard.hpp index 75d23a8..dc6d718 100644 --- a/include/boost/contract/scoped.hpp +++ b/include/boost/contract/guard.hpp @@ -1,6 +1,6 @@ -#ifndef BOOST_CONTRACT_SCOPED_HPP_ -#define BOOST_CONTRACT_SCOPED_HPP_ +#ifndef BOOST_CONTRACT_GUARD_HPP_ +#define BOOST_CONTRACT_GUARD_HPP_ /** @file */ @@ -11,26 +11,27 @@ #include /** @cond */ #include +#include /** @endcond */ namespace boost { namespace contract { -class scoped { // Copyable (as shallow *). +class guard { // Copyable as shared * (OK also for RAII). public: - // All implicit to allow `scoped c = ...`. + // All implicit to allow `guard c = ...`. template - /* implicit */ scoped(set_precondition_postcondition const& contract) : + /* implicit */ guard(set_precondition_postcondition const& contract) : check_(contract.check_) {} - /* implicit */ scoped(set_precondition_only const& contract) : + /* implicit */ guard(set_precondition_only const& contract) : check_(contract.check_) {} template - /* implicit */ scoped(set_postcondition_only const& contract) : + /* implicit */ guard(set_postcondition_only const& contract) : check_(contract.check_) {} - /* implicit */ scoped(set_nothing const& contract) : + /* implicit */ guard(set_nothing const& contract) : check_(contract.check_) {} private: diff --git a/include/boost/contract/oldof.hpp b/include/boost/contract/oldof.hpp index 6485c8c..fdc593c 100644 --- a/include/boost/contract/oldof.hpp +++ b/include/boost/contract/oldof.hpp @@ -5,6 +5,7 @@ /** @file */ #include +#include #include /** @cond */ #include @@ -75,7 +76,7 @@ bool copy_old() { #ifdef BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS return false; // Post checking disabled, so never copy old values. #else - return true; + return !boost::contract::aux::check_guard::checking(); #endif } @@ -83,7 +84,8 @@ bool copy_old(virtual_* v) { #ifdef BOOST_CONTRACT_CONFIG_NO_POSTCONDITIONS return false; // Post checking disabled, so never copy old values. #else - return !v || v->action_ == boost::contract::virtual_::copy_oldof; + if(v) return v->action_ == boost::contract::virtual_::copy_oldof; + else return !boost::contract::aux::check_guard::checking(); #endif } @@ -98,12 +100,14 @@ public: value_(boost::make_shared(old_value)) {} // T's one single copy. // TODO: I might be able to use unique_ptr here instead of shared_ptr. That - // might be the true for the pointer that holds contract and call as well... + // might be true for the pointer that holds contract and call as well... // do some testing to figure that out (unique_ptr adds less overhead). template operator boost::shared_ptr() { - if(!v_) { + if(!v_ && boost::contract::aux::check_guard::checking()) { + // Return null shared ptr (see after if statement). + } else if(!v_) { BOOST_CONTRACT_AUX_DEBUG(value_); boost::shared_ptr old_value = boost::static_pointer_cast(value_); diff --git a/include/boost/contract/public_member.hpp b/include/boost/contract/public_member.hpp index 3204f0c..f3e6579 100644 --- a/include/boost/contract/public_member.hpp +++ b/include/boost/contract/public_member.hpp @@ -15,14 +15,14 @@ namespace boost { namespace contract { -// For public static member functions. +// For static members. template set_precondition_postcondition<> public_member() { return set_precondition_postcondition<>(boost::make_shared< boost::contract::aux::public_static_member >()); } -// For non-virtual of class with no bases. +// For non-virtual, non-overriding members. template set_precondition_postcondition<> public_member(C* obj) { return set_precondition_postcondition<>(boost::make_shared< @@ -33,11 +33,24 @@ set_precondition_postcondition<> public_member(C* obj) { C, boost::contract::aux::none > - >(0, obj, boost::contract::aux::none::value, - boost::contract::aux::none::value)); + >(static_cast(0), obj, boost::contract::aux:: + none::value, boost::contract::aux::none::value)); } -// For virtual members of class with no bases. +// NOTE: O and R (optionally) allowed only when v is present because: +// * An overriding func must override a base func declared virtual so with +// v extra param, thus the overriding func must also always have v (i.e., O +// might be present only if v is also present). +// However, the first appearing virtual func (e.g., in root class) will not +// override any previously declared virtual func so does not need O (i.e., O +// always optional). +// Furthermore, F needs to be specified only together with O. +// * R is only used for virtual functions (i.e., R might be present only if v +// is also present). +// However, R is never specified, not even for virtual functions, when the +// return type is void (i.e., R always optional). + +// For virtual, non-overriding, void members. template set_precondition_postcondition<> public_member(virtual_* v, C* obj) { return set_precondition_postcondition<>(boost::make_shared< @@ -52,17 +65,7 @@ set_precondition_postcondition<> public_member(virtual_* v, C* obj) { boost::contract::aux::none::value)); } -// TODO: R should be specified *only* when v is present. If F present but not -// v then R should NOT be specified. Because an overriding functions must -// always use v even if no longer decl virtual so to overload correct func -// from base class with v param (otherwise most compilers will give a warning -// and overloading will not work) so "virtual result" R never needed unless v -// is present... actually, this meas also F is there only when v is there! -// -// O, [R], F allowed only when v is present! -// - -// For virtual members of class with no bases. +// For virtual, non-overriding, non-void members. template set_precondition_postcondition public_member(virtual_* v, R& r, C* obj) { return set_precondition_postcondition(boost::make_shared< @@ -76,24 +79,9 @@ set_precondition_postcondition public_member(virtual_* v, R& r, C* obj) { >(v, obj, r, boost::contract::aux::none::value)); } -// TODO: Support configurable function arity. -// arity = 0 +/* Overriding (arity = 0) */ -// For non-virtual members of class with bases. -template -set_precondition_postcondition<> public_member(F, C* obj) { - return set_precondition_postcondition<>(boost::make_shared< - boost::contract::aux::public_member< - O, - boost::contract::aux::none, - F, - C, - boost::contract::aux::none - > - >(0, obj, boost::contract::aux::none::value)); -} - -// For virtual members of class with bases. +// For virtual, overriding, void members. template set_precondition_postcondition<> public_member(virtual_* v, F, C* obj) { return set_precondition_postcondition<>(boost::make_shared< @@ -108,26 +96,26 @@ set_precondition_postcondition<> public_member(virtual_* v, F, C* obj) { boost::contract::aux::none::value)); } -// arity = 1 - -template -set_precondition_postcondition<> public_member(F, C* obj, A0& a0) { - return set_precondition_postcondition<>(boost::make_shared< +// For virtual, overriding, non-void members of class with bases. +template +set_precondition_postcondition public_member(virtual_* v, R& r, F, C* obj) { + return set_precondition_postcondition(boost::make_shared< boost::contract::aux::public_member< O, - boost::contract::aux::none, + R, F, C, - A0 + boost::contract::aux::none > - >(0, obj, a0)); + >(v, obj, r, boost::contract::aux::none::value)); } +/* Overriding (arity = 1) */ + template -set_precondition_postcondition public_member( +set_precondition_postcondition<> public_member( virtual_* v, F, C* obj, A0& a0) { - return set_precondition_postcondition( - boost::make_shared< + return set_precondition_postcondition<>(boost::make_shared< boost::contract::aux::public_member< O, boost::contract::aux::none, diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 41bc928..aa42031 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -20,9 +20,11 @@ subdir-run protected_member : body_throw ; subdir-run private_member : bases ; subdir-run private_member : body_throw ; -subdir-run free_function : nominal ; +subdir-run free_function : main ; subdir-run free_function : body_throw ; +subdir-run disable : checking ; + subdir-run set : nothing ; subdir-run set : pre_only ; subdir-run set : post_only ; diff --git a/test/constructor/bases.cpp b/test/constructor/bases.cpp index 9821d6f..089810d 100644 --- a/test/constructor/bases.cpp +++ b/test/constructor/bases.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -50,7 +50,7 @@ struct t BOOST_CONTRACT_OLDOF(z_type::eval(z)); boost::shared_ptr old_l = BOOST_CONTRACT_OLDOF(l_type::eval(l)); - boost::contract::scoped c = boost::contract::constructor(this) + boost::contract::guard c = boost::contract::constructor(this) .postcondition([&] { out << Id << "::ctor::post" << std::endl; BOOST_CONTRACT_ASSERT(k_ == old_z->value); @@ -108,7 +108,7 @@ struct c BOOST_CONTRACT_OLDOF(y_type::eval(y)); boost::shared_ptr old_m = BOOST_CONTRACT_OLDOF(m_type::eval(m)); - boost::contract::scoped c = boost::contract::constructor(this) + boost::contract::guard c = boost::contract::constructor(this) .postcondition([&] { out << "c::ctor::post" << std::endl; BOOST_CONTRACT_ASSERT(j_ == old_y->value); @@ -178,7 +178,7 @@ struct a BOOST_CONTRACT_OLDOF(x_type::eval(x)); boost::shared_ptr old_n = BOOST_CONTRACT_OLDOF(n_type::eval(n)); - boost::contract::scoped c = boost::contract::constructor(this) + boost::contract::guard c = boost::contract::constructor(this) .postcondition([&] { out << "a::ctor::post" << std::endl; BOOST_CONTRACT_ASSERT(i_ == old_x->value); diff --git a/test/constructor/body_throw.cpp b/test/constructor/body_throw.cpp index 23882c3..5db98d3 100644 --- a/test/constructor/body_throw.cpp +++ b/test/constructor/body_throw.cpp @@ -4,7 +4,7 @@ #include "../aux_/oteststream.hpp" #include #include -#include +#include #include #include @@ -25,7 +25,7 @@ struct c out << "c::ctor::pre" << std::endl; }) { - boost::contract::scoped c = boost::contract::constructor(this) + boost::contract::guard c = boost::contract::constructor(this) .postcondition([&] { out << "c::ctor::post" << std::endl; }) @@ -52,7 +52,7 @@ struct b out << "b::ctor::pre" << std::endl; }) { - boost::contract::scoped c = boost::contract::constructor(this) + boost::contract::guard c = boost::contract::constructor(this) .postcondition([&] { out << "b::ctor::post" << std::endl; }) @@ -77,7 +77,7 @@ struct a out << "a::ctor::pre" << std::endl; }) { - boost::contract::scoped c = boost::contract::constructor(this) + boost::contract::guard c = boost::contract::constructor(this) .postcondition([&] { out << "a::ctor::post" << std::endl; }) diff --git a/test/constructor/no_pre-error.cpp b/test/constructor/no_pre-error.cpp index a5c16d6..de17b98 100644 --- a/test/constructor/no_pre-error.cpp +++ b/test/constructor/no_pre-error.cpp @@ -2,11 +2,11 @@ // Test constructor cannot use `.precondition(...)`. #include -#include +#include struct a { a() { - boost::contract::scoped c = boost::contract::constructor(this) + boost::contract::guard c = boost::contract::constructor(this) .precondition([] {}) // Error (must use constructor_precondition). ; } diff --git a/test/destructor/bases.cpp b/test/destructor/bases.cpp index 21af829..180b925 100644 --- a/test/destructor/bases.cpp +++ b/test/destructor/bases.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include @@ -32,7 +32,7 @@ struct t { virtual ~t() { boost::shared_ptr old_l = BOOST_CONTRACT_OLDOF(l_type::eval(l)); - boost::contract::scoped c = boost::contract::destructor(this) + boost::contract::guard c = boost::contract::destructor(this) .postcondition([old_l] { out << Id << "::dtor::post" << std::endl; BOOST_CONTRACT_ASSERT(t::l.value == old_l->value - 1); @@ -75,7 +75,7 @@ struct c virtual ~c() { boost::shared_ptr old_m = BOOST_CONTRACT_OLDOF(m_type::eval(m)); - boost::contract::scoped c = boost::contract::destructor(this) + boost::contract::guard c = boost::contract::destructor(this) .postcondition([old_m] { out << "c::dtor::post" << std::endl; BOOST_CONTRACT_ASSERT(c::m.value == old_m->value - 1); @@ -124,7 +124,7 @@ struct a virtual ~a() { boost::shared_ptr old_n = BOOST_CONTRACT_OLDOF(n_type::eval(n)); - boost::contract::scoped c = boost::contract::destructor(this) + boost::contract::guard c = boost::contract::destructor(this) .postcondition([old_n] { out << "a::dtor::post" << std::endl; BOOST_CONTRACT_ASSERT(a::n.value == old_n->value - 1); diff --git a/test/destructor/body_throw.cpp b/test/destructor/body_throw.cpp index 4f2d5f3..ccb0ad3 100644 --- a/test/destructor/body_throw.cpp +++ b/test/destructor/body_throw.cpp @@ -4,7 +4,7 @@ #include "../aux_/oteststream.hpp" #include #include -#include +#include #include #include #include @@ -18,7 +18,7 @@ struct c { static void static_invariant() { out << "c::static_inv" << std::endl; } ~c() { - boost::contract::scoped c = boost::contract::destructor(this) + boost::contract::guard c = boost::contract::destructor(this) .postcondition([&] { out << "c::dtor::post" << std::endl; }) @@ -41,7 +41,7 @@ struct b struct e {}; ~b() { - boost::contract::scoped c = boost::contract::destructor(this) + boost::contract::guard c = boost::contract::destructor(this) .postcondition([&] { out << "b::dtor::post" << std::endl; }) @@ -62,7 +62,7 @@ struct a static void static_invariant() { out << "a::static_inv" << std::endl; } ~a() { - boost::contract::scoped c = boost::contract::destructor(this) + boost::contract::guard c = boost::contract::destructor(this) .postcondition([&] { out << "a::dtor::post" << std::endl; }) diff --git a/test/destructor/no_pre-error.cpp b/test/destructor/no_pre-error.cpp index e6ee623..51aa052 100644 --- a/test/destructor/no_pre-error.cpp +++ b/test/destructor/no_pre-error.cpp @@ -2,11 +2,11 @@ // Test destructor cannot use `.precondition(...)`. #include -#include +#include struct a { ~a() { - boost::contract::scoped c = boost::contract::destructor(this) + boost::contract::guard c = boost::contract::destructor(this) .precondition([] {}) // Error (no dtor func arg so never pre). ; } diff --git a/test/disable/checking.cpp b/test/disable/checking.cpp new file mode 100644 index 0000000..2bf1d24 --- /dev/null +++ b/test/disable/checking.cpp @@ -0,0 +1,112 @@ + +// Test contract checking and old value copies disabled within contracts. + +#include "../aux_/oteststream.hpp" +#include "../aux_/cpcnt.hpp" +#include +#include +#include +#include +#include +#include +#include + +boost::contract::aux::test::oteststream out; + +struct a { + void invariant() const { out << "a::inv" << std::endl; } + static void static_invariant() { out << "a::static_inv" << std::endl; } + + struct x_tag; typedef boost::contract::aux::test::cpcnt x_type; + + int f(x_type& x) { + int result; + boost::shared_ptr old_x = BOOST_CONTRACT_OLDOF( + x_type::eval(x)); + boost::contract::guard c = boost::contract::public_member(this) + .precondition([&] { out << "a::f::pre" << std::endl; }) + .postcondition([&] { + out << "a::f::post" << std::endl; + BOOST_CONTRACT_ASSERT(x.value == -old_x->value); + BOOST_CONTRACT_ASSERT(result == old_x->value); + }) + ; + out << "a::f::body" << std::endl; + result = x.value; + x.value = -x.value; + return result; + } +}; + +bool call_f() { + a aa; + a::x_type x; x.value = -123; + return aa.f(x) == -123; +} + +struct b { + void invariant() const { out << "b::inv" << std::endl; } + static void static_invariant() { out << "b::static_inv" << std::endl; } + + void g() { + boost::contract::guard c = boost::contract::public_member(this) + .precondition([&] { + out << "b::g::pre" << std::endl; + BOOST_CONTRACT_ASSERT(call_f()); + }) + .postcondition([&] { + out << "b::g::post" << std::endl; + BOOST_CONTRACT_ASSERT(call_f()); + }) + ; + out << "b::g::body" << std::endl; + } +}; + +int main() { + std::ostringstream ok; + b bb; + + out.str(""); + bb.g(); + ok.str(""); ok + << "b::static_inv" << std::endl + << "b::inv" << std::endl + + << "b::g::pre" << std::endl + // Test only f's body (but not its contract) executed here. + << "a::f::body" << std::endl + + << "b::g::body" << std::endl + + << "b::static_inv" << std::endl + << "b::inv" << std::endl + + << "b::g::post" << std::endl + // Test only f's body (but not its contract) executed here. + << "a::f::body" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + // Test old values not copied for disabled contracts. + BOOST_TEST_EQ(a::x_type::copies(), 0); BOOST_TEST_EQ(a::x_type::evals(), 0); + + out << std::endl; + + out.str(""); + call_f(); + // Double check a call to f outside another contract checks f's contracts. + ok.str(""); ok + << "a::static_inv" << std::endl + << "a::inv" << std::endl + << "a::f::pre" << std::endl + << "a::f::body" << std::endl + << "a::static_inv" << std::endl + << "a::inv" << std::endl + << "a::f::post" << std::endl + ; + BOOST_TEST(out.eq(ok.str())); + + return boost::report_errors(); +} + diff --git a/test/free_function/body_throw.cpp b/test/free_function/body_throw.cpp index b5e86d3..42186b2 100644 --- a/test/free_function/body_throw.cpp +++ b/test/free_function/body_throw.cpp @@ -3,7 +3,7 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include @@ -12,7 +12,7 @@ boost::contract::aux::test::oteststream out; struct e {}; void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .precondition([&] { out << "f::pre" << std::endl; }) .postcondition([&] { out << "f::post" << std::endl; }) ; diff --git a/test/free_function/nominal.cpp b/test/free_function/main.cpp similarity index 94% rename from test/free_function/nominal.cpp rename to test/free_function/main.cpp index e973cd4..c2de3fe 100644 --- a/test/free_function/nominal.cpp +++ b/test/free_function/main.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -22,7 +22,7 @@ bool swap(x_type& x, y_type& y) { BOOST_CONTRACT_OLDOF(x_type::eval(x)); boost::shared_ptr old_y = BOOST_CONTRACT_OLDOF(y_type::eval(y)); - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .precondition([&] { out << "swap::pre" << std::endl; BOOST_CONTRACT_ASSERT(x.value != y.value); diff --git a/test/private_member/bases.cpp b/test/private_member/bases.cpp index 7f4a75d..1bfa04a 100644 --- a/test/private_member/bases.cpp +++ b/test/private_member/bases.cpp @@ -4,7 +4,7 @@ #include "../aux_/oteststream.hpp" #include #include -#include +#include #include #include @@ -16,7 +16,7 @@ struct b { private: virtual void f() { - boost::contract::scoped c = boost::contract::private_member() + boost::contract::guard c = boost::contract::private_member() .precondition([&] { out << "b::f::pre" << std::endl; }) @@ -42,7 +42,7 @@ struct a private: virtual void f() { - boost::contract::scoped c = boost::contract::private_member() + boost::contract::guard c = boost::contract::private_member() .precondition([&] { out << "a::f::pre" << std::endl; }) diff --git a/test/private_member/body_throw.cpp b/test/private_member/body_throw.cpp index 99b7dac..b632061 100644 --- a/test/private_member/body_throw.cpp +++ b/test/private_member/body_throw.cpp @@ -3,7 +3,7 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include @@ -19,7 +19,7 @@ struct a { private: virtual void f() { - boost::contract::scoped c = boost::contract::private_member() + boost::contract::guard c = boost::contract::private_member() .precondition([&] { out << "a::f::pre" << std::endl; }) .postcondition([&] { out << "a::f::post" << std::endl; }) ; diff --git a/test/protected_member/bases.cpp b/test/protected_member/bases.cpp index 38c7006..c2339ba 100644 --- a/test/protected_member/bases.cpp +++ b/test/protected_member/bases.cpp @@ -4,7 +4,7 @@ #include "../aux_/oteststream.hpp" #include #include -#include +#include #include #include @@ -16,7 +16,7 @@ struct b { protected: virtual void f() { - boost::contract::scoped c = boost::contract::protected_member() + boost::contract::guard c = boost::contract::protected_member() .precondition([&] { out << "b::f::pre" << std::endl; }) @@ -42,7 +42,7 @@ struct a protected: virtual void f() { - boost::contract::scoped c = boost::contract::protected_member() + boost::contract::guard c = boost::contract::protected_member() .precondition([&] { out << "a::f::pre" << std::endl; }) diff --git a/test/protected_member/body_throw.cpp b/test/protected_member/body_throw.cpp index 38f5d60..ae1ed16 100644 --- a/test/protected_member/body_throw.cpp +++ b/test/protected_member/body_throw.cpp @@ -3,7 +3,7 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include @@ -19,7 +19,7 @@ struct a { protected: virtual void f() { - boost::contract::scoped c = boost::contract::protected_member() + boost::contract::guard c = boost::contract::protected_member() .precondition([&] { out << "a::f::pre" << std::endl; }) .postcondition([&] { out << "a::f::post" << std::endl; }) ; diff --git a/test/public_member/bases.hpp b/test/public_member/bases.hpp index 53e208a..1280f5d 100644 --- a/test/public_member/bases.hpp +++ b/test/public_member/bases.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -56,7 +56,7 @@ result_type& t::f(s_type& s, boost::contract::virtual_* v) { BOOST_CONTRACT_OLDOF(v, z_type::eval(z)); boost::shared_ptr old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); - boost::contract::scoped c = boost::contract::public_member(v, result, this) + boost::contract::guard c = boost::contract::public_member(v, result, this) .precondition([&] { out << Id << "::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(s.value[0] == Id); @@ -101,7 +101,7 @@ struct c BOOST_CONTRACT_OLDOF(v, y_type::eval(y)); boost::shared_ptr old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); - boost::contract::scoped c = boost::contract::public_member< + boost::contract::guard c = boost::contract::public_member< override_f>(v, result, &c::f, this, s) .precondition([&] { out << "c::f::pre" << std::endl; @@ -180,7 +180,7 @@ struct a BOOST_CONTRACT_OLDOF(v, x_type::eval(x)); boost::shared_ptr old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); - boost::contract::scoped c = boost::contract::public_member< + boost::contract::guard c = boost::contract::public_member< override_f>(v, result, &a::f, this, s) .precondition([&] { out << "a::f::pre" << std::endl; diff --git a/test/public_member/body_throw.cpp b/test/public_member/body_throw.cpp index 4854f26..0b11752 100644 --- a/test/public_member/body_throw.cpp +++ b/test/public_member/body_throw.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include @@ -19,7 +19,7 @@ struct c { struct e {}; virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::scoped c = boost::contract::public_member(v, this) + boost::contract::guard c = boost::contract::public_member(v, this) .precondition([&] { out << "c::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(false); // To check derived pre. @@ -44,7 +44,7 @@ struct b struct e {}; virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::scoped c = boost::contract::public_member( + boost::contract::guard c = boost::contract::public_member( v, &b::f, this) .precondition([&] { out << "b::f::pre" << std::endl; @@ -71,7 +71,7 @@ struct a struct e {}; void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::scoped c = boost::contract::public_member( + boost::contract::guard c = boost::contract::public_member( v, &a::f, this) .precondition([&] { out << "a::f::pre" << std::endl; }) .postcondition([&] { out << "a::f::post" << std::endl; }) diff --git a/test/public_member/static.cpp b/test/public_member/static.cpp index 2739d1a..ba531e7 100644 --- a/test/public_member/static.cpp +++ b/test/public_member/static.cpp @@ -4,7 +4,7 @@ #include "../aux_/oteststream.hpp" #include #include -#include +#include #include #include @@ -15,7 +15,7 @@ struct b { static void static_invariant() { out << "b::static_inv" << std::endl; } static void f() { - boost::contract::scoped c = boost::contract::public_member() + boost::contract::guard c = boost::contract::public_member() .precondition([&] { out << "b::f::pre" << std::endl; }) @@ -38,7 +38,7 @@ struct a static void static_invariant() { out << "a::static_inv" << std::endl; } static void f() { - boost::contract::scoped c = boost::contract::public_member() + boost::contract::guard c = boost::contract::public_member() .precondition([&] { out << "a::f::pre" << std::endl; }) diff --git a/test/public_member/static_body_throw.cpp b/test/public_member/static_body_throw.cpp index 7dbdce6..72f5bb0 100644 --- a/test/public_member/static_body_throw.cpp +++ b/test/public_member/static_body_throw.cpp @@ -3,7 +3,7 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include @@ -16,7 +16,7 @@ struct a { struct e {}; static void f() { - boost::contract::scoped c = boost::contract::public_member() + boost::contract::guard c = boost::contract::public_member() .precondition([&] { out << "a::f::pre" << std::endl; }) diff --git a/test/set/nothing.cpp b/test/set/nothing.cpp index 06c551a..1882852 100644 --- a/test/set/nothing.cpp +++ b/test/set/nothing.cpp @@ -3,14 +3,14 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include boost::contract::aux::test::oteststream out; void f() { - boost::contract::scoped c = boost::contract::free_function(); + boost::contract::guard c = boost::contract::free_function(); out << "f::body" << std::endl; } diff --git a/test/set/post_only.cpp b/test/set/post_only.cpp index e2bf5df..6fde1ac 100644 --- a/test/set/post_only.cpp +++ b/test/set/post_only.cpp @@ -3,14 +3,14 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include boost::contract::aux::test::oteststream out; void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .postcondition([] { out << "f::post" << std::endl; }) ; out << "f::body" << std::endl; diff --git a/test/set/post_post-error.cpp b/test/set/post_post-error.cpp index d7b98c8..d27a8f8 100644 --- a/test/set/post_post-error.cpp +++ b/test/set/post_post-error.cpp @@ -2,10 +2,10 @@ // Test multiple post error (for free func, but same for all contracts). #include -#include +#include void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .postcondition([] {}) .postcondition([] {}) // Error (multiple post). ; diff --git a/test/set/post_pre.cpp b/test/set/post_pre.cpp index 9bc20b7..c96500d 100644 --- a/test/set/post_pre.cpp +++ b/test/set/post_pre.cpp @@ -3,14 +3,14 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include boost::contract::aux::test::oteststream out; void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .postcondition([] { out << "f::post" << std::endl; }) .precondition([] { out << "f::pre" << std::endl; }) ; diff --git a/test/set/post_pre_post-error.cpp b/test/set/post_pre_post-error.cpp index d363b0e..dea5424 100644 --- a/test/set/post_pre_post-error.cpp +++ b/test/set/post_pre_post-error.cpp @@ -2,10 +2,10 @@ // Test multi post around pre error (for free func, but same for all contracts). #include -#include +#include void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .postcondition([] {}) .precondition([] {}) .postcondition([] {}) // Error (multiple post around pre). diff --git a/test/set/pre_only.cpp b/test/set/pre_only.cpp index 945773f..99694cd 100644 --- a/test/set/pre_only.cpp +++ b/test/set/pre_only.cpp @@ -3,14 +3,14 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include boost::contract::aux::test::oteststream out; void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .precondition([] { out << "f::pre" << std::endl; }) ; out << "f::body" << std::endl; diff --git a/test/set/pre_post.cpp b/test/set/pre_post.cpp index 604e3d1..8a4d6eb 100644 --- a/test/set/pre_post.cpp +++ b/test/set/pre_post.cpp @@ -3,14 +3,14 @@ #include "../aux_/oteststream.hpp" #include -#include +#include #include #include boost::contract::aux::test::oteststream out; void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .precondition([] { out << "f::pre" << std::endl; }) .postcondition([] { out << "f::post" << std::endl; }) ; diff --git a/test/set/pre_post_pre-error.cpp b/test/set/pre_post_pre-error.cpp index 685512c..7abe97b 100644 --- a/test/set/pre_post_pre-error.cpp +++ b/test/set/pre_post_pre-error.cpp @@ -2,10 +2,10 @@ // Test multi pre around post error (for free func, but same for all contracts). #include -#include +#include void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .precondition([] {}) .postcondition([] {}) .precondition([] {}) // Error (multiple pre around post). diff --git a/test/set/pre_pre-error.cpp b/test/set/pre_pre-error.cpp index 66f788d..94a1a90 100644 --- a/test/set/pre_pre-error.cpp +++ b/test/set/pre_pre-error.cpp @@ -2,10 +2,10 @@ // Test multiple pre error (for free func, but same for all contracts). #include -#include +#include void f() { - boost::contract::scoped c = boost::contract::free_function() + boost::contract::guard c = boost::contract::free_function() .precondition([] {}) .precondition([] {}) // Error (multiple pre). ;