mirror of
https://github.com/boostorg/contract.git
synced 2026-02-27 04:52:22 +00:00
added .except(...), renamed old_ptr_noncopyable to old_ptr_if_copyable, and renamed OLDOF to OLD
This commit is contained in:
@@ -25,9 +25,15 @@ never be used directly by programmers.
|
||||
@see @RefSect{getting_started, Getting Started}
|
||||
*/
|
||||
|
||||
// TODO: Clearly separate const and const volatile inv checked by mutable+const and volatile+const_volatile func respectively (see related email to Boost).
|
||||
|
||||
// TODO: Add a macro ALL_DISABLE_NOTHING to turn-off disabling assertions within assertions for all contracts, not just preconditions (do I still need PRECONDITIONS_DISABLE_NOTHING then?).
|
||||
|
||||
// TODO: Consider using a trait like boost::contract::is_copy_constructible<T> (or has_old<T>) instead of boost::is_copy_constructible<T> directly (so programmers can specialize it to avoid old copies of specify types T without affecting other parts of the program that might be using boost::is_copy_constructible). Then maybe I should also introduce a trait to make the copy instead of directly using the copy constructor... so to allow for maximum customization..
|
||||
|
||||
// TODO: Document that boost::contract::function() can be used to program contracts for lambda functions. And also "abused" a bit to program pre/postconditions for any arbitrary scope of code in function body.
|
||||
|
||||
// TODO: Document that friends do not in general check invariants so their contracts are usually programmed using function(). But if a function friend of an object takes an instance of that object as a parameter and therefore is essentially part of the object's public API, then programmers can make that explicit by using public_function(obj) after function() to program the friend function contract (but note that in general friends functions can take instances of multiple different objects because the same function can be friend of different classes).
|
||||
// TODO: Document that friends do not in general check invariants so their contracts are usually programmed using function(). But if a function friend of an object takes an instance of that object as a parameter and therefore is essentially part of the object's public API, then programmers can make that explicit by using public_function(obj) after function() to program the friend function contract (but note that in general friends functions can take instances of multiple different objects because the same function can be friend of different classes). Also add a test (under test/public_function/...) and an example for friend.
|
||||
|
||||
// TODO: Document that noexcept (and exception throw(...)) specifications of the enclosing function apply to contracts. So if a contract handler is set so contract failures throw, noexcept function will still not throw, they will always terminate (because that's what users of such functions except, even if the function fails in any way, including the function contract fails).
|
||||
|
||||
@@ -35,13 +41,13 @@ never be used directly by programmers.
|
||||
|
||||
// TODO: Document (in Getting Started) that some example source code has `//[...` and `//]` tags used to import example code in Quickbook docs (so doc's examples always up to date with code).
|
||||
|
||||
// TODO: Add a macro ALL_DISABLE_NOTHING to turn-off disabling assertions within assertions for all contracts, not just preconditions (do I still need PRECONDITIONS_DISABLE_NOTHING then?).
|
||||
// TODO: Document that result is NOT accessible in .except's functor because function threw. Old values are accessible in both post and except so OLDOF copies disabled on if both except and post checking disabled (NO_EXCEPTS && NO_POSTCONDITIONS). except will have its own failure handler except_failure, check disabling macro NO_EXCEPTS, etc.
|
||||
|
||||
// TODO: Consider a better name for contract::detail::check_guard (it's confusing with old contract::guard and with current check_base::guard)... maybe I can call it contract::detail::disable?
|
||||
// TODO: Document that contract for constexpr functions cannot be supported at the moment because constexpr functions cannot: (1) declare local variables of (literal) types with non-trivial constexpr destructors (needed by this lib to check inv, post, and except at exit), (2) call other (constexpr) functions with try-catch statements (used by this lib to report assertion failure and catch any other exception that might be thrown by the evaluation of the asserted conditions), (3) use lambda functions (use by this for convenience to program functors that check per and post). Also note that even if supported, contracts for constexpr probably will not use old values (because constexpr prevent the function from having any side effect visible to the caller, variables around such side-effects are usually the candidates for old value copies) and subcontracting (because constexpr functions cannot be virtual).
|
||||
|
||||
// TODO: Consider using a trait like boost::contract::is_copy_constructible<T> (or has_old<T>) instead of boost::is_copy_constructible<T> directly (so programmers can specialize it to avoid old copies of specify types T without affecting other parts of the program that might be using boost::is_copy_constructible). Then maybe I should also introduce a trait to make the copy instead of directly using the copy constructor... so to allow for maximum customization..
|
||||
// TODO: Documentation updates based on all emails to Boost (review all emails).
|
||||
|
||||
// TODO: Add .except(...) that is checked at function exit when body throws (in contrast to postconditions). result is NOT accessible in .except's functor because function threw. Old values are accessible in both post and except so OLDOF copies disabled on if both except and post checking disabled (NO_EXCEPTS && NO_POSTCONDITIONS). except will have its own failure handler except_failure, check disabling macro NO_EXCEPTS, etc.
|
||||
// TODO: Documentation updates based on all n-papers that I read recently (review notes I wrote on all papers), add those n-papers to the Bibliography section, and add P0380 (the most recent proposal) to the feature comparison table.
|
||||
|
||||
#include <boost/contract/detail/all_core_headers.hpp>
|
||||
#include <boost/contract/assert.hpp>
|
||||
|
||||
@@ -20,7 +20,7 @@ Facility to assert contract conditions.
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
#include <boost/contract/detail/assert.hpp>
|
||||
#define BOOST_CONTRACT_ASSERT(condition) \
|
||||
{ BOOST_CONTRACT_DETAIL_ASSERT(condition); }
|
||||
BOOST_CONTRACT_DETAIL_ASSERT(condition) /* no `;` here */
|
||||
#else
|
||||
/**
|
||||
Preferred way to assert contract conditions.
|
||||
|
||||
@@ -12,9 +12,9 @@ RAII object to check contracts.
|
||||
*/
|
||||
|
||||
#include <boost/contract/detail/all_core_headers.hpp>
|
||||
#include <boost/contract/detail/condition/check_base.hpp>
|
||||
#include <boost/contract/detail/condition/cond_base.hpp>
|
||||
#include <boost/contract/detail/assert.hpp>
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#include <boost/contract/detail/auto_ptr.hpp>
|
||||
#include <boost/contract/detail/debug.hpp>
|
||||
#include <boost/contract/detail/name.hpp>
|
||||
@@ -24,14 +24,15 @@ RAII object to check contracts.
|
||||
|
||||
/** @cond */
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#define BOOST_CONTRACT_CHECK_CTOR_DEF_(contract_type) \
|
||||
: check_(const_cast<contract_type&>(contract).check_.release()) \
|
||||
: cond_(const_cast<contract_type&>(contract).cond_.release()) \
|
||||
{ \
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(check_); \
|
||||
check_->guard(); \
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(cond_); \
|
||||
cond_->initialize(); \
|
||||
}
|
||||
#else
|
||||
#define BOOST_CONTRACT_CHECK_CTOR_DEF_(contract_type) {}
|
||||
@@ -41,10 +42,10 @@ RAII object to check contracts.
|
||||
#define BOOST_CONTRACT_CHECK_(assertion) \
|
||||
{ \
|
||||
try { \
|
||||
if(!boost::contract::detail::check_guard::checking()) { \
|
||||
if(!boost::contract::detail::checking::already()) { \
|
||||
/* this name somewhat unique to min var shadow warnings */ \
|
||||
boost::contract::detail::check_guard \
|
||||
BOOST_CONTRACT_DETAIL_NAME2(checking, __LINE__); \
|
||||
boost::contract::detail::checking\
|
||||
BOOST_CONTRACT_DETAIL_NAME2(chk, __LINE__); \
|
||||
{ assertion; } \
|
||||
} \
|
||||
} catch(...) { boost::contract::check_failure(); } \
|
||||
@@ -57,6 +58,7 @@ RAII object to check contracts.
|
||||
|
||||
/* PUBLIC */
|
||||
|
||||
// Requires trailing semicolon to be consistent with ASSERT.
|
||||
#define BOOST_CONTRACT_CHECK(condition) \
|
||||
BOOST_CONTRACT_CHECK_(BOOST_CONTRACT_DETAIL_ASSERT(condition))
|
||||
|
||||
@@ -88,11 +90,12 @@ public:
|
||||
contract checking ownership is transfered from the copied object to this
|
||||
object).
|
||||
*/
|
||||
check(check const& other) // Copy ctor moves check_ pointer to dest.
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
check(check const& other) // Copy ctor moves cond_ pointer to dest.
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
: check_(const_cast<check&>(other).check_.release())
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
: cond_(const_cast<check&>(other).cond_.release())
|
||||
#endif
|
||||
{}
|
||||
|
||||
@@ -112,11 +115,11 @@ public:
|
||||
otherwise this is always @c void.
|
||||
*/
|
||||
template<typename VirtualResult>
|
||||
/* implicit */ check(specify_precondition_old_postcondition<VirtualResult>
|
||||
const& contract)
|
||||
/* implicit */ check(specify_precondition_old_postcondition_except<
|
||||
VirtualResult> const& contract)
|
||||
#ifndef DOXYGEN
|
||||
BOOST_CONTRACT_CHECK_CTOR_DEF_(
|
||||
specify_precondition_old_postcondition<VirtualResult>)
|
||||
specify_precondition_old_postcondition_except<VirtualResult>)
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
@@ -138,10 +141,11 @@ public:
|
||||
otherwise this is always @c void.
|
||||
*/
|
||||
template<typename VirtualResult>
|
||||
/* implicit */ check(specify_old_postcondition<VirtualResult> const&
|
||||
/* implicit */ check(specify_old_postcondition_except<VirtualResult> const&
|
||||
contract)
|
||||
#ifndef DOXYGEN
|
||||
BOOST_CONTRACT_CHECK_CTOR_DEF_(specify_old_postcondition<VirtualResult>)
|
||||
BOOST_CONTRACT_CHECK_CTOR_DEF_(
|
||||
specify_old_postcondition_except<VirtualResult>)
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
@@ -163,11 +167,18 @@ public:
|
||||
otherwise this is always @c void.
|
||||
*/
|
||||
template<typename VirtualResult>
|
||||
/* implicit */ check(specify_postcondition_only<VirtualResult> const&
|
||||
/* implicit */ check(specify_postcondition_except<VirtualResult> const&
|
||||
contract)
|
||||
#ifndef DOXYGEN
|
||||
BOOST_CONTRACT_CHECK_CTOR_DEF_(
|
||||
specify_postcondition_only<VirtualResult>)
|
||||
specify_postcondition_except<VirtualResult>)
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
|
||||
/* implicit */ check(specify_except const& contract)
|
||||
#ifndef DOXYGEN
|
||||
BOOST_CONTRACT_CHECK_CTOR_DEF_(specify_except)
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
@@ -210,11 +221,12 @@ public:
|
||||
private:
|
||||
check& operator=(check const&); // Cannot copy outside of `check c = ...`.
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
boost::contract::detail::auto_ptr<boost::contract::detail::check_base>
|
||||
check_;
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
boost::contract::detail::auto_ptr<boost::contract::detail::cond_base>
|
||||
cond_;
|
||||
#endif
|
||||
/** @endcond */
|
||||
};
|
||||
|
||||
@@ -12,12 +12,12 @@ Program contracts for constructors.
|
||||
*/
|
||||
|
||||
#include <boost/contract/detail/all_core_headers.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS)
|
||||
#include <boost/contract/detail/operation/constructor.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS)
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost { namespace contract {
|
||||
@@ -39,14 +39,14 @@ postconditions when the enclosing class has no invariants.
|
||||
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}).
|
||||
*/
|
||||
template<class Class>
|
||||
specify_old_postcondition<> constructor(Class* obj) {
|
||||
specify_old_postcondition_except<> constructor(Class* obj) {
|
||||
// Must #if also on ..._PRECONDITIONS here because specify_... is generic.
|
||||
#if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS)
|
||||
return specify_old_postcondition<>(
|
||||
return specify_old_postcondition_except<>(
|
||||
new boost::contract::detail::constructor<Class>(obj));
|
||||
#else
|
||||
return specify_old_postcondition<>();
|
||||
return specify_old_postcondition_except<>();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -88,10 +88,10 @@ public:
|
||||
template<typename F>
|
||||
explicit constructor_precondition(F const& f) {
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
if(boost::contract::detail::check_guard::checking()) return;
|
||||
if(boost::contract::detail::checking::already()) return;
|
||||
try {
|
||||
#ifndef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
|
||||
boost::contract::detail::check_guard checking;
|
||||
boost::contract::detail::checking k;
|
||||
#endif
|
||||
f();
|
||||
} catch(...) { precondition_failure(from_constructor); }
|
||||
|
||||
@@ -30,11 +30,11 @@ namespace boost {
|
||||
class virtual_;
|
||||
|
||||
namespace detail {
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_Z(1,
|
||||
/* is_friend = */ 0, OO, RR, FF, CC, AArgs);
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_WITH_SUBCONTRACTING_Z(1,
|
||||
/* is_friend = */ 0, OO, RR, FF, CC, AArgs);
|
||||
|
||||
template<typename RR, class CC>
|
||||
class check_pre_post_inv;
|
||||
class cond_with_inv;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,11 +136,11 @@ class access : private boost::noncopyable {
|
||||
// increase compilation times (I experimented replacing all friends with
|
||||
// public and got the same compilation times).
|
||||
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_Z(1,
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_WITH_SUBCONTRACTING_Z(1,
|
||||
/* is_friend = */ 1, OO, RR, FF, CC, AArgs);
|
||||
|
||||
template<typename RR, class CC>
|
||||
friend class boost::contract::detail::check_pre_post_inv;
|
||||
friend class boost::contract::detail::cond_with_inv;
|
||||
|
||||
BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTIONS_Z(1,
|
||||
OO, RR, FF, CC, AArgs, vv, rr, ff, oobj, aargs)
|
||||
|
||||
@@ -164,7 +164,7 @@ Facilities to configure this library compile-time and run-time behaviour.
|
||||
defined, this library will execute the code expanded by the macro instead of
|
||||
calling @c assert (if programmers prefer to throw an exception, etc.).
|
||||
*/
|
||||
#define BOOST_CONTRACT_ON_MISSING_GUARD
|
||||
#define BOOST_CONTRACT_ON_MISSING_CHECK_DECL
|
||||
#endif
|
||||
|
||||
#ifdef DOXYGEN
|
||||
@@ -245,7 +245,7 @@ Facilities to configure this library compile-time and run-time behaviour.
|
||||
#define BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) && \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) && \
|
||||
defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) && \
|
||||
defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS)
|
||||
/**
|
||||
@@ -269,9 +269,10 @@ Facilities to configure this library compile-time and run-time behaviour.
|
||||
|
||||
// Ctor pre checked separately and outside RAII so not part of this #define.
|
||||
#ifdef BOOST_CONTRACT_NO_CONSTRUCTORS
|
||||
#error "define NO_ENTRY_INVARIANTS, NO_EXIT_INVARIANTS, and NO_POSTCONDITIONS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
#error "define NO_ENTRY_INVARIANTS, NO_EXIT_INVARIANTS, NO_POSTCONDITIONS, and NO_EXCEPTS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_INVARIANTS) && \
|
||||
defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
/**
|
||||
Defined by this library if constructor contracts are not being checked by
|
||||
@RefFunc{boost::contract::constructor}.
|
||||
@@ -294,9 +295,10 @@ Facilities to configure this library compile-time and run-time behaviour.
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_CONTRACT_NO_DESTRUCTORS
|
||||
#error "define NO_ENTRY_INVARIANTS, NO_EXIT_INVARIANTS, and NO_POSTCONDITIONS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
#error "define NO_ENTRY_INVARIANTS, NO_EXIT_INVARIANTS, NO_POSTCONDITIONS, and NO_EXCEPTS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_INVARIANTS) && \
|
||||
defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
/**
|
||||
Defined by this library if destructor contracts are not being checked by
|
||||
@RefFunc{boost::contract::destructor}.
|
||||
@@ -318,10 +320,11 @@ Facilities to configure this library compile-time and run-time behaviour.
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
|
||||
#error "define NO_ENTRY_INVARIANTS, NO_PRECONDITIONS, NO_EXIT_INVARIANTS, and NO_POSTCONDITIONS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \
|
||||
#error "define NO_ENTRY_INVARIANTS, NO_PRECONDITIONS, NO_EXIT_INVARIANTS, NO_POSTCONDITIONS, and NO_EXCEPTS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_INVARIANTS) && \
|
||||
defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
/**
|
||||
Defined by this library if public function contracts are not being checked
|
||||
by @RefFunc{boost::contract::public_function}.
|
||||
@@ -342,9 +345,10 @@ Facilities to configure this library compile-time and run-time behaviour.
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_CONTRACT_NO_FUNCTIONS
|
||||
#error "define NO_PRECONDITIONS and NO_POSTCONDITIONS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#error "define NO_PRECONDITIONS, NO_POSTCONDITIONS, and NO_EXCEPTS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_PRECONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_POSTCONDITIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
/**
|
||||
Defined by this library if non-member, private, and protected function
|
||||
contracts are not being checked by @RefFunc{boost::contract::function}.
|
||||
@@ -365,8 +369,8 @@ Facilities to configure this library compile-time and run-time behaviour.
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_CONTRACT_NO_ALL
|
||||
#error "define NO_ENTRY_INVARIANTS, NO_PRECONDITIONS, NO_EXIT_INVARIANTS, and NO_POSTCONDITIONS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_CONSTRUCTORS) && \
|
||||
#error "define NO_ENTRY_INVARIANTS, NO_PRECONDITIONS, NO_EXIT_INVARIANTS, NO_POSTCONDITIONS, and NO_EXCEPTS instead"
|
||||
#elif defined(BOOST_CONTRACT_NO_CONSTRUCTORS) && \
|
||||
defined(BOOST_CONTRACT_NO_DESTRUCTORS) && \
|
||||
defined(BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS) && \
|
||||
defined(BOOST_CONTRACT_NO_FUNCTIONS)
|
||||
|
||||
@@ -315,6 +315,16 @@ This is often called only internally by this library.
|
||||
void /** @cond */ BOOST_CONTRACT_DETAIL_DECLSPEC /** @endcond */
|
||||
postcondition_failure(from where) /* can throw */;
|
||||
|
||||
from_failure_handler /** @cond */ BOOST_CONTRACT_DETAIL_DECLSPEC /** @endcond */
|
||||
set_except_failure(from_failure_handler const& f)
|
||||
/** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
|
||||
|
||||
from_failure_handler /** @cond */ BOOST_CONTRACT_DETAIL_DECLSPEC /** @endcond */
|
||||
get_except_failure() /** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
|
||||
|
||||
void /** @cond */ BOOST_CONTRACT_DETAIL_DECLSPEC /** @endcond */
|
||||
except_failure(from where) /* can throw */;
|
||||
|
||||
/**
|
||||
Set the entry invariant failure handler.
|
||||
Set a new entry invariant failure handler and return the old one.
|
||||
@@ -407,6 +417,10 @@ void /** @cond */ BOOST_CONTRACT_DETAIL_DECLSPEC /** @endcond */
|
||||
set_invariant_failure(from_failure_handler const& f)
|
||||
/** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
|
||||
|
||||
void /** @cond */ BOOST_CONTRACT_DETAIL_DECLSPEC /** @endcond */
|
||||
set_specification_failure(from_failure_handler const& f)
|
||||
/** @cond */ BOOST_NOEXCEPT_OR_NOTHROW /** @endcond */;
|
||||
|
||||
// Cannot provide a `set_all_failures` because check handler has no `from`.
|
||||
|
||||
} } // namespace
|
||||
|
||||
@@ -13,32 +13,102 @@ Facilities to specify preconditions, old value assignments, and postconditions.
|
||||
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#include <boost/contract/detail/decl.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
#include <boost/contract/detail/condition/check_base.hpp>
|
||||
#include <boost/contract/detail/condition/check_pre_post.hpp>
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/detail/condition/cond_base.hpp>
|
||||
#include <boost/contract/detail/condition/cond_with_post.hpp>
|
||||
#include <boost/contract/detail/auto_ptr.hpp>
|
||||
#include <boost/contract/detail/none.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/detail/debug.hpp>
|
||||
#endif
|
||||
#include <boost/config.hpp>
|
||||
|
||||
// NOTE: Do not use inheritance here to avoid extra runtime costs (code
|
||||
// duplication avoid via macros instead).
|
||||
|
||||
/* PRIVATE */
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#define BOOST_CONTRACT_SPECIFY_COND_CTOR_(ctor_name, cond_type) \
|
||||
explicit ctor_name(cond_type* cond) : cond_(cond) {} \
|
||||
boost::contract::detail::auto_ptr<cond_type> cond_;
|
||||
|
||||
#define BOOST_CONTRACT_SPECIFY_COND_RELEASE_ cond_.release()
|
||||
#else
|
||||
#define BOOST_CONTRACT_SPECIFY_COND_CTOR_(cond_type) /* nothing */
|
||||
|
||||
#define BOOST_CONTRACT_SPECIFY_COND_RELEASE_ /* nothing */
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
#define BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_ \
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(cond_); \
|
||||
cond_->set_pre(f); \
|
||||
return specify_old_postcondition_except<VirtualResult>( \
|
||||
BOOST_CONTRACT_SPECIFY_COND_RELEASE_);
|
||||
#else
|
||||
#define BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_ \
|
||||
return specify_old_postcondition_except<VirtualResult>( \
|
||||
BOOST_CONTRACT_SPECIFY_COND_RELEASE_);
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#define BOOST_CONTRACT_SPECIFY_OLD_IMPL_ \
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(cond_); \
|
||||
cond_->set_old(f); \
|
||||
return specify_postcondition_except<VirtualResult>( \
|
||||
BOOST_CONTRACT_SPECIFY_COND_RELEASE_);
|
||||
#else
|
||||
#define BOOST_CONTRACT_SPECIFY_OLD_IMPL_ \
|
||||
return specify_postcondition_except<VirtualResult>( \
|
||||
BOOST_CONTRACT_SPECIFY_COND_RELEASE_);
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#define BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_ \
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(cond_); \
|
||||
cond_->set_post(f); \
|
||||
return specify_except(BOOST_CONTRACT_SPECIFY_COND_RELEASE_);
|
||||
#else
|
||||
#define BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_ \
|
||||
return specify_except(BOOST_CONTRACT_SPECIFY_COND_RELEASE_);
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
#define BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ \
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(cond_); \
|
||||
cond_->set_except(f); \
|
||||
return specify_nothing(BOOST_CONTRACT_SPECIFY_COND_RELEASE_);
|
||||
#else
|
||||
#define BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_ \
|
||||
return specify_nothing(BOOST_CONTRACT_SPECIFY_COND_RELEASE_);
|
||||
#endif
|
||||
|
||||
/* CODE */
|
||||
|
||||
namespace boost {
|
||||
namespace contract {
|
||||
class virtual_;
|
||||
|
||||
template<typename VR>
|
||||
class specify_precondition_old_postcondition;
|
||||
|
||||
template<typename VR>
|
||||
class specify_old_postcondition;
|
||||
class specify_precondition_old_postcondition_except;
|
||||
|
||||
template<typename VR>
|
||||
class specify_postcondition_only;
|
||||
class specify_old_postcondition_except;
|
||||
|
||||
template<typename VR>
|
||||
class specify_postcondition_except;
|
||||
|
||||
class specify_except;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,28 +135,51 @@ public:
|
||||
|
||||
/** @cond */
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
typedef boost::contract::detail::check_base check_type;
|
||||
|
||||
explicit specify_nothing(check_type* check) : check_(check) {}
|
||||
|
||||
boost::contract::detail::auto_ptr<check_type> check_;
|
||||
#endif
|
||||
BOOST_CONTRACT_SPECIFY_COND_CTOR_(specify_nothing,
|
||||
boost::contract::detail::cond_base)
|
||||
|
||||
// Friends (used to limit library's public API).
|
||||
|
||||
friend class check;
|
||||
|
||||
template<typename VR>
|
||||
friend class specify_precondition_old_postcondition;
|
||||
friend class specify_precondition_old_postcondition_except;
|
||||
|
||||
template<typename VR>
|
||||
friend class specify_old_postcondition;
|
||||
friend class specify_old_postcondition_except;
|
||||
|
||||
template<typename VR>
|
||||
friend class specify_postcondition_only;
|
||||
friend class specify_postcondition_except;
|
||||
|
||||
friend class specify_except;
|
||||
/** @endcond */
|
||||
};
|
||||
|
||||
class specify_except { // Copyable (as *).
|
||||
public:
|
||||
~specify_except() BOOST_NOEXCEPT_IF(false) {}
|
||||
|
||||
template<typename F>
|
||||
specify_nothing except(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_
|
||||
}
|
||||
|
||||
/** @cond */
|
||||
private:
|
||||
BOOST_CONTRACT_SPECIFY_COND_CTOR_(specify_except,
|
||||
boost::contract::detail::cond_base)
|
||||
|
||||
// Friends (used to limit library's public API).
|
||||
friend class check;
|
||||
|
||||
template<typename VR>
|
||||
friend class specify_precondition_old_postcondition_except;
|
||||
|
||||
template<typename VR>
|
||||
friend class specify_old_postcondition_except;
|
||||
|
||||
template<typename VR>
|
||||
friend class specify_postcondition_except;
|
||||
/** @endcond */
|
||||
};
|
||||
|
||||
@@ -99,7 +192,7 @@ Allow to program functors this library will call to check postconditions.
|
||||
this is always @c void.
|
||||
*/
|
||||
template<typename VirtualResult = void>
|
||||
class specify_postcondition_only { // Copyable (as *).
|
||||
class specify_postcondition_except { // Copyable (as *).
|
||||
public:
|
||||
/**
|
||||
Destruct this object.
|
||||
@@ -108,7 +201,7 @@ public:
|
||||
terminating the program (see
|
||||
@RefFunc{boost::contract::set_precondition_failure}, etc.).
|
||||
*/
|
||||
~specify_postcondition_only() BOOST_NOEXCEPT_IF(false) {}
|
||||
~specify_postcondition_except() BOOST_NOEXCEPT_IF(false) {}
|
||||
|
||||
/**
|
||||
Allow to specify postconditions.
|
||||
@@ -130,38 +223,27 @@ public:
|
||||
not allow to specify any additional contract.
|
||||
*/
|
||||
template<typename F>
|
||||
specify_nothing postcondition(F const& f) {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(check_);
|
||||
check_->set_post(f);
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
return specify_nothing(check_.release());
|
||||
#else
|
||||
return specify_nothing();
|
||||
#endif
|
||||
specify_except postcondition(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
specify_nothing except(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_
|
||||
}
|
||||
|
||||
/** @cond */
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
typedef boost::contract::detail::check_pre_post<typename boost::contract
|
||||
::detail::none_if_void<VirtualResult>::type> check_type;
|
||||
|
||||
explicit specify_postcondition_only(check_type* check) :
|
||||
check_(check) {}
|
||||
|
||||
boost::contract::detail::auto_ptr<check_type> check_;
|
||||
#endif
|
||||
BOOST_CONTRACT_SPECIFY_COND_CTOR_(
|
||||
specify_postcondition_except,
|
||||
boost::contract::detail::cond_with_post<typename
|
||||
boost::contract::detail::none_if_void<VirtualResult>::type>
|
||||
)
|
||||
|
||||
// Friends (used to limit library's public API).
|
||||
friend class check;
|
||||
friend class specify_precondition_old_postcondition<VirtualResult>;
|
||||
friend class specify_old_postcondition<VirtualResult>;
|
||||
friend class specify_precondition_old_postcondition_except<VirtualResult>;
|
||||
friend class specify_old_postcondition_except<VirtualResult>;
|
||||
/** @endcond */
|
||||
};
|
||||
|
||||
@@ -175,7 +257,7 @@ body execution and to check postconditions.
|
||||
this is always @c void.
|
||||
*/
|
||||
template<typename VirtualResult = void>
|
||||
class specify_old_postcondition { // Copyable (as *).
|
||||
class specify_old_postcondition_except { // Copyable (as *).
|
||||
public:
|
||||
/**
|
||||
Destruct this object.
|
||||
@@ -184,7 +266,7 @@ public:
|
||||
terminating the program (see
|
||||
@RefFunc{boost::contract::set_precondition_failure}, etc.).
|
||||
*/
|
||||
~specify_old_postcondition() BOOST_NOEXCEPT_IF(false) {}
|
||||
~specify_old_postcondition_except() BOOST_NOEXCEPT_IF(false) {}
|
||||
|
||||
/**
|
||||
Allow to specify old value assignments to execute just before the function
|
||||
@@ -210,18 +292,8 @@ public:
|
||||
allows to optionally specify postconditions.
|
||||
*/
|
||||
template<typename F>
|
||||
specify_postcondition_only<VirtualResult> old(F const& f) {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(check_);
|
||||
check_->set_old(f);
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
return specify_postcondition_only<VirtualResult>(check_.release());
|
||||
#else
|
||||
return specify_postcondition_only<VirtualResult>();
|
||||
#endif
|
||||
specify_postcondition_except<VirtualResult> old(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_OLD_IMPL_
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,44 +316,33 @@ public:
|
||||
not allow to specify any additional contract.
|
||||
*/
|
||||
template<typename F>
|
||||
specify_nothing postcondition(F const& f) {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(check_);
|
||||
check_->set_post(f);
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
return specify_nothing(check_.release());
|
||||
#else
|
||||
return specify_nothing();
|
||||
#endif
|
||||
specify_except postcondition(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
specify_nothing except(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_
|
||||
}
|
||||
|
||||
/** @cond */
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
typedef boost::contract::detail::check_pre_post<typename boost::contract
|
||||
::detail::none_if_void<VirtualResult>::type> check_type;
|
||||
|
||||
explicit specify_old_postcondition(check_type* check) :
|
||||
check_(check) {}
|
||||
|
||||
boost::contract::detail::auto_ptr<check_type> check_;
|
||||
#endif
|
||||
BOOST_CONTRACT_SPECIFY_COND_CTOR_(
|
||||
specify_old_postcondition_except,
|
||||
boost::contract::detail::cond_with_post<typename
|
||||
boost::contract::detail::none_if_void<VirtualResult>::type>
|
||||
)
|
||||
|
||||
// Friends (used to limit library's public API).
|
||||
|
||||
friend class check;
|
||||
friend class specify_precondition_old_postcondition<VirtualResult>;
|
||||
friend class specify_precondition_old_postcondition_except<VirtualResult>;
|
||||
|
||||
template<class C>
|
||||
friend specify_old_postcondition<> constructor(C*);
|
||||
friend specify_old_postcondition_except<> constructor(C*);
|
||||
|
||||
template<class C>
|
||||
friend specify_old_postcondition<> destructor(C*);
|
||||
friend specify_old_postcondition_except<> destructor(C*);
|
||||
/** @endcond */
|
||||
};
|
||||
|
||||
@@ -300,7 +361,7 @@ template<
|
||||
= void
|
||||
#endif
|
||||
>
|
||||
class specify_precondition_old_postcondition { // Copyable (as *).
|
||||
class specify_precondition_old_postcondition_except { // Copyable (as *).
|
||||
public:
|
||||
/**
|
||||
Destruct this object.
|
||||
@@ -309,7 +370,7 @@ public:
|
||||
terminating the program (see
|
||||
@RefFunc{boost::contract::set_precondition_failure}, etc.).
|
||||
*/
|
||||
~specify_precondition_old_postcondition() BOOST_NOEXCEPT_IF(false) {}
|
||||
~specify_precondition_old_postcondition_except() BOOST_NOEXCEPT_IF(false) {}
|
||||
|
||||
/**
|
||||
Allow to specify preconditions.
|
||||
@@ -326,18 +387,8 @@ public:
|
||||
to optionally specify old value assignments and postconditions.
|
||||
*/
|
||||
template<typename F>
|
||||
specify_old_postcondition<VirtualResult> precondition(F const& f) {
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(check_);
|
||||
check_->set_pre(f);
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
return specify_old_postcondition<VirtualResult>(check_.release());
|
||||
#else
|
||||
return specify_old_postcondition<VirtualResult>();
|
||||
#endif
|
||||
specify_old_postcondition_except<VirtualResult> precondition(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -364,18 +415,8 @@ public:
|
||||
allows to optionally specify postconditions.
|
||||
*/
|
||||
template<typename F>
|
||||
specify_postcondition_only<VirtualResult> old(F const& f) {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(check_);
|
||||
check_->set_old(f);
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
return specify_postcondition_only<VirtualResult>(check_.release());
|
||||
#else
|
||||
return specify_postcondition_only<VirtualResult>();
|
||||
#endif
|
||||
specify_postcondition_except<VirtualResult> old(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_OLD_IMPL_
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,51 +439,40 @@ public:
|
||||
not allow to specify any additional contract.
|
||||
*/
|
||||
template<typename F>
|
||||
specify_nothing postcondition(F const& f) {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(check_);
|
||||
check_->set_post(f);
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
return specify_nothing(check_.release());
|
||||
#else
|
||||
return specify_nothing();
|
||||
#endif
|
||||
specify_except postcondition(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_POSTCONDITION_IMPL_
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
specify_nothing except(F const& f) {
|
||||
BOOST_CONTRACT_SPECIFY_EXCEPT_IMPL_
|
||||
}
|
||||
|
||||
/** @cond */
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
typedef boost::contract::detail::check_pre_post<typename boost::contract
|
||||
::detail::none_if_void<VirtualResult>::type> check_type;
|
||||
|
||||
explicit specify_precondition_old_postcondition(check_type* check) :
|
||||
check_(check) {}
|
||||
|
||||
boost::contract::detail::auto_ptr<check_type> check_;
|
||||
#endif
|
||||
BOOST_CONTRACT_SPECIFY_COND_CTOR_(
|
||||
specify_precondition_old_postcondition_except,
|
||||
boost::contract::detail::cond_with_post<typename
|
||||
boost::contract::detail::none_if_void<VirtualResult>::type>
|
||||
)
|
||||
|
||||
// Friends (used to limit library's public API).
|
||||
|
||||
friend class check;
|
||||
friend specify_precondition_old_postcondition<> function();
|
||||
friend specify_precondition_old_postcondition_except<> function();
|
||||
|
||||
template<class C>
|
||||
friend specify_precondition_old_postcondition<> public_function();
|
||||
friend specify_precondition_old_postcondition_except<> public_function();
|
||||
|
||||
template<class C>
|
||||
friend specify_precondition_old_postcondition<> public_function(C*);
|
||||
friend specify_precondition_old_postcondition_except<> public_function(C*);
|
||||
|
||||
template<class C>
|
||||
friend specify_precondition_old_postcondition<> public_function(
|
||||
friend specify_precondition_old_postcondition_except<> public_function(
|
||||
virtual_*, C*);
|
||||
|
||||
template<typename VR, class C>
|
||||
friend specify_precondition_old_postcondition<VR> public_function(
|
||||
friend specify_precondition_old_postcondition_except<VR> public_function(
|
||||
virtual_*, VR&, C*);
|
||||
|
||||
BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTIONS_Z(1,
|
||||
|
||||
@@ -16,6 +16,9 @@ Facility to declare virtual public functions with contracts.
|
||||
#include <boost/noncopyable.hpp>
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#include <boost/any.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
@@ -24,7 +27,7 @@ Facility to declare virtual public functions with contracts.
|
||||
namespace boost {
|
||||
namespace contract {
|
||||
namespace detail {
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_Z(1,
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_WITH_SUBCONTRACTING_Z(1,
|
||||
/* is_friend = */ 0, OO, RR, FF, CC, AArgs);
|
||||
}
|
||||
}
|
||||
@@ -61,9 +64,10 @@ class virtual_ : private boost::noncopyable { // Avoid copy queue, stack, etc.
|
||||
|
||||
enum action_enum {
|
||||
// virtual_ always hold/passed by ptr so null ptr used for user call.
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
no_action,
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
@@ -85,13 +89,17 @@ class virtual_ : private boost::noncopyable { // Avoid copy queue, stack, etc.
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
pop_old_copy,
|
||||
check_post,
|
||||
pop_old_init = check_post // These must be the same value.
|
||||
pop_old_init = check_post, // These must be the same value.
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
check_except,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
explicit virtual_(action_enum a) :
|
||||
action_(a)
|
||||
, failed_(false)
|
||||
@@ -102,16 +110,19 @@ class virtual_ : private boost::noncopyable { // Avoid copy queue, stack, etc.
|
||||
{}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
action_enum action_;
|
||||
bool failed_;
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
std::queue<boost::shared_ptr<void> > old_inits_;
|
||||
std::stack<boost::shared_ptr<void> > old_copies_;
|
||||
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
boost::any result_ptr_; // Result for virtual and overriding functions.
|
||||
char const* result_type_name_;
|
||||
bool result_optional_;
|
||||
@@ -122,7 +133,7 @@ class virtual_ : private boost::noncopyable { // Avoid copy queue, stack, etc.
|
||||
friend bool copy_old(virtual_*);
|
||||
friend class old_pointer;
|
||||
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_Z(1,
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_WITH_SUBCONTRACTING_Z(1,
|
||||
/* is_friend = */ 1, OO, RR, FF, CC, AArgs);
|
||||
/** @endcond */
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ Program contracts for destructors.
|
||||
*/
|
||||
|
||||
#include <boost/contract/detail/all_core_headers.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_DESTRUCTORS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_DESTRUCTORS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS)
|
||||
#include <boost/contract/detail/operation/destructor.hpp>
|
||||
#endif
|
||||
@@ -35,14 +35,14 @@ postconditions when the enclosing class has no invariants.
|
||||
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}).
|
||||
*/
|
||||
template<class Class>
|
||||
specify_old_postcondition<> destructor(Class* obj) {
|
||||
specify_old_postcondition_except<> destructor(Class* obj) {
|
||||
// Must #if also on ..._PRECONDITIONS here because specify_... is generic.
|
||||
#if !defined(BOOST_CONTRACT_NO_DESTRUCTORS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_DESTRUCTORS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS)
|
||||
return specify_old_postcondition<>(
|
||||
return specify_old_postcondition_except<>(
|
||||
new boost::contract::detail::destructor<Class>(obj));
|
||||
#else
|
||||
return specify_old_postcondition<>();
|
||||
return specify_old_postcondition_except<>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
|
||||
// Use ternary operator `?:` and no trailing `;` here to allow `if(...) ASSERT(
|
||||
// ...); else ...` (won't compile if expands using an if statement instead even
|
||||
// if wrapped by {}, and else won't compile if expands trailing `;`).
|
||||
#define BOOST_CONTRACT_DETAIL_ASSERT(condition) \
|
||||
{ \
|
||||
if(!(condition)) { \
|
||||
throw boost::contract::assertion_failure(__FILE__, __LINE__, \
|
||||
BOOST_PP_STRINGIZE(condition)); \
|
||||
} \
|
||||
}
|
||||
/* no if-statement here */ \
|
||||
((condition) ? (void*)0 : throw boost::contract::assertion_failure( \
|
||||
__FILE__, __LINE__, BOOST_PP_STRINGIZE(condition))) /* no ; here */
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_DETAIL_CHECK_GUARD_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_CHECK_GUARD_HPP_
|
||||
#ifndef BOOST_CONTRACT_DETAIL_CHECKING_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_CHECKING_HPP_
|
||||
|
||||
// Copyright (C) 2008-2016 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||
@@ -20,14 +20,15 @@ namespace boost { namespace contract { namespace detail {
|
||||
#pragma warning(disable: 4251) // Member w/o DLL spec (mutex_ type).
|
||||
#endif
|
||||
|
||||
class BOOST_CONTRACT_DETAIL_DECLSPEC check_guard :
|
||||
// RAII facility to disable assertions while checking other assertions.
|
||||
class BOOST_CONTRACT_DETAIL_DECLSPEC checking :
|
||||
private boost::noncopyable // Non-copyable resource (might use mutex, etc.).
|
||||
{
|
||||
public:
|
||||
explicit check_guard();
|
||||
~check_guard();
|
||||
explicit checking();
|
||||
~checking();
|
||||
|
||||
static bool checking();
|
||||
static bool already();
|
||||
|
||||
private:
|
||||
static bool checking_;
|
||||
@@ -1,129 +0,0 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_DETAIL_CHECK_BASE_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_CHECK_BASE_HPP_
|
||||
|
||||
// Copyright (C) 2008-2016 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||
// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
|
||||
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#include <boost/function.hpp>
|
||||
#endif
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#ifndef BOOST_CONTRACT_ON_MISSING_GUARD
|
||||
#include <cassert>
|
||||
#endif
|
||||
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
class check_base : // Base to hold all contract objects for RAII.
|
||||
private boost::noncopyable // Avoid copying possible user's ftor captures.
|
||||
{
|
||||
public:
|
||||
explicit check_base(boost::contract::from from) :
|
||||
BOOST_CONTRACT_ERROR_missing_guard_declaration(false)
|
||||
, guard_asserted_(false)
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
, from_(from)
|
||||
, failed_(false)
|
||||
#endif
|
||||
{}
|
||||
|
||||
// Override for checking on exit (but overrides call `assert_guarded()`).
|
||||
virtual ~check_base() BOOST_NOEXCEPT_IF(false) {
|
||||
if(!guard_asserted_) assert_guarded();
|
||||
}
|
||||
|
||||
void assert_guarded() { // Derived dtors must assert this at entry.
|
||||
guard_asserted_ = true;
|
||||
#ifdef BOOST_CONTRACT_ON_MISSING_GUARD
|
||||
if(!BOOST_CONTRACT_ERROR_missing_guard_declaration) {
|
||||
BOOST_CONTRACT_ON_MISSING_GUARD;
|
||||
}
|
||||
#else
|
||||
assert(BOOST_CONTRACT_ERROR_missing_guard_declaration);
|
||||
#endif
|
||||
}
|
||||
|
||||
void guard() { // Must be called by contract guard ctor.
|
||||
BOOST_CONTRACT_ERROR_missing_guard_declaration = true;
|
||||
this->init(); // All inits (pre, old, post) done after guard decl.
|
||||
}
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
template<typename F>
|
||||
void set_pre(F const& f) { pre_ = f; }
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
template<typename F>
|
||||
void set_old(F const& f) { old_ = f; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void init() {} // Override for checking on entry.
|
||||
|
||||
// Return true if actually checked calling user ftor.
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
bool check_pre(bool throw_on_failure = false) {
|
||||
if(failed()) return true;
|
||||
try { if(pre_) pre_(); else return false; }
|
||||
catch(...) {
|
||||
// Subcontracted pre must throw on failure (instead of
|
||||
// calling failure handler) so to be checked in logic-or.
|
||||
if(throw_on_failure) throw;
|
||||
fail(&boost::contract::precondition_failure);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
void copy_old() {
|
||||
if(failed()) return;
|
||||
try { if(old_) old_(); }
|
||||
catch(...) { fail(&boost::contract::postcondition_failure); }
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
void fail(void (*h)(boost::contract::from)) {
|
||||
failed(true);
|
||||
if(h) h(from_);
|
||||
}
|
||||
|
||||
// Virtual so overriding pub func can use virtual_::failed_ instead.
|
||||
virtual bool failed() const { return failed_; }
|
||||
virtual void failed(bool value) { failed_ = value; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool BOOST_CONTRACT_ERROR_missing_guard_declaration;
|
||||
bool guard_asserted_; // Avoid throwing twice from dtors (undef behavior).
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
boost::contract::from from_;
|
||||
bool failed_;
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
boost::function<void ()> pre_; // Use Boost.Function to also...
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
boost::function<void ()> old_; // ...handle lambdas, binds, etc.
|
||||
#endif
|
||||
};
|
||||
|
||||
} } } // namespace
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
155
include/boost/contract/detail/condition/cond_base.hpp
Normal file
155
include/boost/contract/detail/condition/cond_base.hpp
Normal file
@@ -0,0 +1,155 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_DETAIL_COND_BASE_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_COND_BASE_HPP_
|
||||
|
||||
// Copyright (C) 2008-2016 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||
// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
|
||||
|
||||
// TODO: Try to see if *all* inheritance can be replaced with some static polymorphism (strategies, policies, etc.) so I will have no virtual functions at all. Then I could measure if there is any compile/run-time change by compiling and running all examples (or tests) on MSVC, GCC, and CLang...
|
||||
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXEPTS)
|
||||
#include <boost/function.hpp>
|
||||
#endif
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#ifndef BOOST_CONTRACT_ON_MISSING_CHECK_DECL
|
||||
#include <cassert>
|
||||
#endif
|
||||
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
class cond_base : // Base to hold all contract objects for RAII.
|
||||
private boost::noncopyable // Avoid copying possible user's ftor captures.
|
||||
{
|
||||
public:
|
||||
explicit cond_base(boost::contract::from from) :
|
||||
BOOST_CONTRACT_ERROR_missing_check_object_declaration(false)
|
||||
, init_asserted_(false)
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
, from_(from)
|
||||
, failed_(false)
|
||||
#endif
|
||||
{}
|
||||
|
||||
// Can override for checking on exit, but should call assert_initialized().
|
||||
virtual ~cond_base() BOOST_NOEXCEPT_IF(false) {
|
||||
// Catch error (but later) even if overrides miss assert_initialized().
|
||||
if(!init_asserted_) assert_initialized();
|
||||
}
|
||||
|
||||
void initialize() { // Must be called by owner ctor (i.e., check class).
|
||||
BOOST_CONTRACT_ERROR_missing_check_object_declaration = true;
|
||||
this->init(); // So all inits (pre, old, post) done after owner decl.
|
||||
}
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
template<typename F>
|
||||
void set_pre(F const& f) { pre_ = f; }
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
template<typename F>
|
||||
void set_old(F const& f) { old_ = f; }
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
template<typename F>
|
||||
void set_except(F const& f) { except_ = f; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void assert_initialized() { // Derived dtors must assert this at entry.
|
||||
init_asserted_ = true;
|
||||
#ifdef BOOST_CONTRACT_ON_MISSING_CHECK_DECL
|
||||
if(!BOOST_CONTRACT_ERROR_missing_check_object_declaration) {
|
||||
BOOST_CONTRACT_ON_MISSING_CHECK_DECL;
|
||||
}
|
||||
#else
|
||||
// Cannot use a macro instead of this ERROR_... directly here
|
||||
// because assert will not expand it in the error message.
|
||||
assert(BOOST_CONTRACT_ERROR_missing_check_object_declaration);
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void init() {} // Override for checking on entry.
|
||||
|
||||
// Return true if actually checked calling user ftor.
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
bool check_pre(bool throw_on_failure = false) {
|
||||
if(failed()) return true;
|
||||
try { if(pre_) pre_(); else return false; }
|
||||
catch(...) {
|
||||
// Subcontracted pre must throw on failure (instead of
|
||||
// calling failure handler) so to be checked in logic-or.
|
||||
if(throw_on_failure) throw;
|
||||
fail(&boost::contract::precondition_failure);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
void copy_old() {
|
||||
if(failed()) return;
|
||||
try { if(old_) old_(); }
|
||||
catch(...) { fail(&boost::contract::postcondition_failure); }
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
void check_except() {
|
||||
if(failed()) return;
|
||||
try { if(except_) except_(); }
|
||||
catch(...) { fail(&boost::contract::except_failure); }
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
void fail(void (*h)(boost::contract::from)) {
|
||||
failed(true);
|
||||
if(h) h(from_);
|
||||
}
|
||||
|
||||
// Virtual so overriding pub func can use virtual_::failed_ instead.
|
||||
virtual bool failed() const { return failed_; }
|
||||
virtual void failed(bool value) { failed_ = value; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool BOOST_CONTRACT_ERROR_missing_check_object_declaration;
|
||||
bool init_asserted_; // Avoid throwing twice from dtors (undef behavior).
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
boost::contract::from from_;
|
||||
bool failed_;
|
||||
#endif
|
||||
// Following use Boost.Function to handle also lambdas, binds, etc.
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
boost::function<void ()> pre_;
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
boost::function<void ()> old_;
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
boost::function<void ()> except_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} } } // namespace
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_DETAIL_CHECK_PRE_POST_INV_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_CHECK_PRE_POST_INV_HPP_
|
||||
#ifndef BOOST_CONTRACT_DETAIL_COND_WITH_INV_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_COND_WITH_INV_HPP_
|
||||
|
||||
// Copyright (C) 2008-2016 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#include <boost/contract/detail/condition/check_pre_post.hpp>
|
||||
#include <boost/contract/detail/condition/cond_with_post.hpp>
|
||||
#ifndef BOOST_CONTRACT_NO_INVARIANTS
|
||||
#include <boost/contract/core/access.hpp>
|
||||
#include <boost/type_traits/add_pointer.hpp>
|
||||
@@ -32,8 +32,8 @@
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
template<typename VR, class C>
|
||||
class check_pre_post_inv : public check_pre_post<VR> { // Non-copyable base.
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) && \
|
||||
class cond_with_inv : public cond_with_post<VR> { // Non-copyable base.
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) && \
|
||||
!defined(BOOST_CONTRACT_PERMISSIVE)
|
||||
BOOST_STATIC_ASSERT_MSG(
|
||||
!boost::contract::access::has_static_invariant_f<
|
||||
@@ -94,11 +94,12 @@ class check_pre_post_inv : public check_pre_post<VR> { // Non-copyable base.
|
||||
|
||||
public:
|
||||
// obj can be 0 for static member functions.
|
||||
explicit check_pre_post_inv(boost::contract::from from, C* obj) :
|
||||
check_pre_post<VR>(from)
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
explicit cond_with_inv(boost::contract::from from, C* obj) :
|
||||
cond_with_post<VR>(from)
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
, obj_(obj)
|
||||
#endif
|
||||
{}
|
||||
@@ -116,9 +117,10 @@ protected:
|
||||
void check_exit_all_inv() { check_inv(false, false, true); }
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
C* object() { return obj_; }
|
||||
#endif
|
||||
|
||||
@@ -183,7 +185,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Check is class's func is inherited from its base types or not.
|
||||
// Check if class's func is inherited from its base types or not.
|
||||
template<template<class> class HasFunc, template<class> class FuncAddr>
|
||||
struct inherited {
|
||||
static bool apply() {
|
||||
@@ -224,9 +226,10 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
C* obj_;
|
||||
#endif
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_DETAIL_CHECK_PRE_POST_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_CHECK_PRE_POST_HPP_
|
||||
#ifndef BOOST_CONTRACT_DETAIL_COND_WITH_POST_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_COND_WITH_POST_HPP_
|
||||
|
||||
// Copyright (C) 2008-2016 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#include <boost/contract/detail/condition/check_base.hpp>
|
||||
#include <boost/contract/detail/condition/cond_base.hpp>
|
||||
#include <boost/contract/detail/none.hpp>
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#include <boost/contract/detail/type_traits/optional.hpp>
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
/* PRIVATE */
|
||||
|
||||
#define BOOST_CONTRACT_DETAIL_CHECK_PRE_POST_DEF_( \
|
||||
#define BOOST_CONTRACT_DETAIL_COND_WITH_POST_DEF_( \
|
||||
result_type, result_param, ftor_type, ftor_var, ftor_call) \
|
||||
public: \
|
||||
template<typename F> \
|
||||
@@ -42,9 +42,9 @@
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
template<typename VR>
|
||||
class check_pre_post : public check_base { // Non-copyable base.
|
||||
class cond_with_post : public cond_base { // Non-copyable base.
|
||||
public:
|
||||
explicit check_pre_post(boost::contract::from from) : check_base(from) {}
|
||||
explicit cond_with_post(boost::contract::from from) : cond_base(from) {}
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
private:
|
||||
@@ -55,7 +55,7 @@ private:
|
||||
VR const&
|
||||
>::type r_type;
|
||||
|
||||
BOOST_CONTRACT_DETAIL_CHECK_PRE_POST_DEF_(
|
||||
BOOST_CONTRACT_DETAIL_COND_WITH_POST_DEF_(
|
||||
r_type,
|
||||
r,
|
||||
void (r_type),
|
||||
@@ -67,12 +67,12 @@ private:
|
||||
};
|
||||
|
||||
template<>
|
||||
class check_pre_post<none> : public check_base { // Non-copyable base.
|
||||
class cond_with_post<none> : public cond_base { // Non-copyable base.
|
||||
public:
|
||||
explicit check_pre_post(boost::contract::from from) : check_base(from) {}
|
||||
explicit cond_with_post(boost::contract::from from) : cond_base(from) {}
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
BOOST_CONTRACT_DETAIL_CHECK_PRE_POST_DEF_(
|
||||
BOOST_CONTRACT_DETAIL_COND_WITH_POST_DEF_(
|
||||
none,
|
||||
unused,
|
||||
void (),
|
||||
@@ -1,6 +1,6 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_HPP_
|
||||
#ifndef BOOST_CONTRACT_DETAIL_COND_WITH_SUBCONTRACTING_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_COND_WITH_SUBCONTRACTING_HPP_
|
||||
|
||||
// Copyright (C) 2008-2016 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||
@@ -8,16 +8,18 @@
|
||||
// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
|
||||
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#endif
|
||||
#include <boost/contract/detail/condition/check_pre_post_inv.hpp>
|
||||
#include <boost/contract/detail/condition/cond_with_inv.hpp>
|
||||
#include <boost/contract/detail/decl.hpp>
|
||||
#include <boost/contract/detail/tvariadic.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/core/virtual.hpp>
|
||||
#include <boost/contract/core/access.hpp>
|
||||
#include <boost/contract/detail/type_traits/optional.hpp>
|
||||
@@ -43,15 +45,17 @@
|
||||
#include <boost/config.hpp>
|
||||
#endif
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/mpl/for_each.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
#include <boost/mpl/pop_front.hpp>
|
||||
#include <boost/mpl/front.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOSOT_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
@@ -61,20 +65,20 @@
|
||||
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
namespace check_subcontracted_pre_post_inv_ {
|
||||
namespace cond_with_subcontracting_ {
|
||||
// Exception signals (must not inherit).
|
||||
class signal_no_error {};
|
||||
class signal_not_checked {};
|
||||
}
|
||||
|
||||
// O, VR, F, and Args-i can be none types (but C cannot).
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_Z(1,
|
||||
/* is_friend = */ 0, O, VR, F, C, Args) : // Non-copyable base.
|
||||
public check_pre_post_inv<VR, C>
|
||||
{
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_WITH_SUBCONTRACTING_Z(1,
|
||||
/* is_friend = */ 0, O, VR, F, C, Args) : public cond_with_inv<VR, C>
|
||||
{ // Non-copyable base.
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
template<class Class, typename Result = boost::mpl::vector<> >
|
||||
class overridden_bases_of {
|
||||
struct search_bases {
|
||||
@@ -141,7 +145,7 @@ BOOST_CONTRACT_DETAIL_DECL_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_Z(1,
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit check_subcontracted_pre_post_inv(
|
||||
explicit cond_with_subcontracting(
|
||||
boost::contract::from from,
|
||||
boost::contract::virtual_* v,
|
||||
C* obj,
|
||||
@@ -150,21 +154,23 @@ public:
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(1,
|
||||
BOOST_CONTRACT_MAX_ARGS, Args, &, args)
|
||||
) :
|
||||
check_pre_post_inv<VR, C>(from, obj)
|
||||
cond_with_inv<VR, C>(from, obj)
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
, r_(r)
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INIT_Z(1,
|
||||
BOOST_CONTRACT_MAX_ARGS, args_, args)
|
||||
#endif
|
||||
{
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
if(v) {
|
||||
base_call_ = true;
|
||||
v_ = v; // Invariant: v_ never null if base_call_.
|
||||
@@ -184,10 +190,11 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
virtual ~check_subcontracted_pre_post_inv() BOOST_NOEXCEPT_IF(false) {
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
virtual ~cond_with_subcontracting() BOOST_NOEXCEPT_IF(false) {
|
||||
if(!base_call_) delete v_;
|
||||
}
|
||||
#endif
|
||||
@@ -203,7 +210,7 @@ protected:
|
||||
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
|
||||
void check_subcontracted_entry_inv() {
|
||||
exec_and(boost::contract::virtual_::check_entry_inv,
|
||||
&check_subcontracted_pre_post_inv::check_entry_inv);
|
||||
&cond_with_subcontracting::check_entry_inv);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -211,7 +218,7 @@ protected:
|
||||
void check_subcontracted_pre() {
|
||||
exec_or(
|
||||
boost::contract::virtual_::check_pre,
|
||||
&check_subcontracted_pre_post_inv::check_pre,
|
||||
&cond_with_subcontracting::check_pre,
|
||||
&boost::contract::precondition_failure
|
||||
);
|
||||
}
|
||||
@@ -220,43 +227,52 @@ protected:
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
void copy_subcontracted_old() {
|
||||
exec_and(boost::contract::virtual_::call_old_copy,
|
||||
&check_subcontracted_pre_post_inv::copy_old_v);
|
||||
&cond_with_subcontracting::copy_virtual_old);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
void check_subcontracted_exit_inv() {
|
||||
exec_and(boost::contract::virtual_::check_exit_inv,
|
||||
&check_subcontracted_pre_post_inv::check_exit_inv);
|
||||
&cond_with_subcontracting::check_exit_inv);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
void check_subcontracted_post() {
|
||||
exec_and(boost::contract::virtual_::check_post,
|
||||
&check_subcontracted_pre_post_inv::check_post_v);
|
||||
&cond_with_subcontracting::check_virtual_post);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#ifndef BOOST_CONTRAT_NO_EXCEPTS
|
||||
void check_subcontracted_except() {
|
||||
exec_and(boost::contract::virtual_::check_except,
|
||||
&cond_with_subcontracting::check_except);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
bool base_call() const { return base_call_; }
|
||||
|
||||
bool failed() const /* override */ {
|
||||
if(v_) return v_->failed_;
|
||||
else return check_base::failed();
|
||||
else return cond_base::failed();
|
||||
}
|
||||
|
||||
void failed(bool value) /* override */ {
|
||||
if(v_) v_->failed_ = value;
|
||||
else check_base::failed(value);
|
||||
else cond_base::failed(value);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
void copy_old_v() {
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
void copy_virtual_old() {
|
||||
boost::contract::virtual_::action_enum a;
|
||||
if(base_call_) {
|
||||
a = v_->action_;
|
||||
@@ -265,8 +281,10 @@ private:
|
||||
this->copy_old();
|
||||
if(base_call_) v_->action_ = a;
|
||||
}
|
||||
#endif
|
||||
|
||||
void check_post_v() {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
void check_virtual_post() {
|
||||
if(base_call_) {
|
||||
boost::contract::virtual_::action_enum a = v_->action_;
|
||||
v_->action_ = boost::contract::virtual_::pop_old_copy;
|
||||
@@ -307,26 +325,27 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
check_post_r<VR>(r);
|
||||
check_virtual_post_with_result<VR>(r);
|
||||
}
|
||||
|
||||
template<typename R_, typename Result>
|
||||
typename boost::enable_if<is_optional<R_> >::type
|
||||
check_post_r(Result const& r) { this->check_post(r); }
|
||||
check_virtual_post_with_result(Result const& r) { this->check_post(r); }
|
||||
|
||||
template<typename R_, typename Result>
|
||||
typename boost::disable_if<is_optional<R_> >::type
|
||||
check_post_r(Result const& r) {
|
||||
check_virtual_post_with_result(Result const& r) {
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(r);
|
||||
this->check_post(*r);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
void exec_and( // Execute action in short-circuit logic-and with bases.
|
||||
boost::contract::virtual_::action_enum a,
|
||||
void (check_subcontracted_pre_post_inv::* f)() = 0
|
||||
void (cond_with_subcontracting::* f)() = 0
|
||||
) {
|
||||
if(failed()) return;
|
||||
if(!base_call_ || v_->action_ == a) {
|
||||
@@ -336,7 +355,7 @@ private:
|
||||
}
|
||||
if(f) (this->*f)();
|
||||
if(base_call_) {
|
||||
throw check_subcontracted_pre_post_inv_::signal_no_error();
|
||||
throw cond_with_subcontracting_::signal_no_error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,7 +364,7 @@ private:
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
void exec_or( // Execute action in short-circuit logic-or with bases.
|
||||
boost::contract::virtual_::action_enum a,
|
||||
bool (check_subcontracted_pre_post_inv::* f)(bool) = 0,
|
||||
bool (cond_with_subcontracting::* f)(bool) = 0,
|
||||
void (*h)(boost::contract::from) = 0
|
||||
) {
|
||||
if(failed()) return;
|
||||
@@ -369,10 +388,9 @@ private:
|
||||
(this->*f)(/* throw_on_failure = */ base_call_) : false;
|
||||
if(base_call_) {
|
||||
if(!checked) {
|
||||
throw check_subcontracted_pre_post_inv_::
|
||||
signal_not_checked();
|
||||
throw cond_with_subcontracting_::signal_not_checked();
|
||||
}
|
||||
throw check_subcontracted_pre_post_inv_::signal_no_error();
|
||||
throw cond_with_subcontracting_::signal_no_error();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -387,8 +405,7 @@ private:
|
||||
if(boost::mpl::empty<Bases>::value) return false;
|
||||
try {
|
||||
call_base(*this)(typename boost::mpl::front<Bases>::type());
|
||||
} catch(check_subcontracted_pre_post_inv_::
|
||||
signal_not_checked const&) {
|
||||
} catch(cond_with_subcontracting_::signal_not_checked const&) {
|
||||
return exec_or_bases<
|
||||
typename boost::mpl::pop_front<Bases>::type>();
|
||||
} catch(...) {
|
||||
@@ -403,13 +420,13 @@ private:
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
class call_base { // Copyable (as &).
|
||||
public:
|
||||
explicit call_base(check_subcontracted_pre_post_inv& me) :
|
||||
me_(me) {}
|
||||
explicit call_base(cond_with_subcontracting& me) : me_(me) {}
|
||||
|
||||
template<class B>
|
||||
void operator()(B*) {
|
||||
@@ -420,8 +437,7 @@ private:
|
||||
try {
|
||||
call<B>(BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_INDEXES_OF(
|
||||
Args));
|
||||
} catch(check_subcontracted_pre_post_inv_::
|
||||
signal_no_error const&) {
|
||||
} catch(cond_with_subcontracting_::signal_no_error const&) {
|
||||
// No error (do not throw).
|
||||
}
|
||||
}
|
||||
@@ -445,16 +461,17 @@ private:
|
||||
);
|
||||
}
|
||||
|
||||
check_subcontracted_pre_post_inv& me_;
|
||||
cond_with_subcontracting& me_;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
VR& r_;
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
boost::contract::virtual_* v_;
|
||||
bool base_call_;
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_TUPLE_Z(1,
|
||||
@@ -36,7 +36,7 @@
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(z, arity, Args) \
|
||||
> \
|
||||
BOOST_PP_EXPR_IIF(is_friend, friend) \
|
||||
boost::contract::specify_precondition_old_postcondition< \
|
||||
boost::contract::specify_precondition_old_postcondition_except< \
|
||||
BOOST_PP_EXPR_IIF(has_result, VR)> \
|
||||
/* no boost::contract:: here for friends (otherwise need fwd decl) */ \
|
||||
public_function( \
|
||||
@@ -99,7 +99,7 @@
|
||||
)
|
||||
#endif
|
||||
|
||||
#define BOOST_CONTRACT_DETAIL_DECL_DETAIL_CHECK_SUBCONTRACTED_PRE_POST_INV_Z( \
|
||||
#define BOOST_CONTRACT_DETAIL_DECL_DETAIL_COND_WITH_SUBCONTRACTING_Z( \
|
||||
z, is_friend, O, VR, F, C, Args) \
|
||||
template< \
|
||||
class O, typename VR, typename F, class C \
|
||||
@@ -112,7 +112,7 @@
|
||||
, \
|
||||
class \
|
||||
) \
|
||||
check_subcontracted_pre_post_inv
|
||||
cond_with_subcontracting
|
||||
|
||||
/* CODE */
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace boost {
|
||||
class virtual_;
|
||||
|
||||
template<typename VR = void>
|
||||
class specify_precondition_old_postcondition;
|
||||
class specify_precondition_old_postcondition_except;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,18 +102,19 @@ void assertion_failure::init() {
|
||||
|
||||
namespace exception_ {
|
||||
enum failure_key {
|
||||
check_key, pre_key, post_key, entry_inv_key, exit_inv_key
|
||||
entry_inv_key, exit_inv_key, pre_key, post_key, except_key, check_key
|
||||
};
|
||||
|
||||
template<failure_key Key>
|
||||
void default_handler() {
|
||||
std::string k = "";
|
||||
switch(Key) {
|
||||
case check_key: k = "check "; break;
|
||||
case pre_key: k = "precondition "; break;
|
||||
case post_key: k = "postcondition "; break;
|
||||
case entry_inv_key: k = "entry invariant "; break;
|
||||
case exit_inv_key: k = "exit invariant "; break;
|
||||
case pre_key: k = "precondition "; break;
|
||||
case post_key: k = "postcondition "; break;
|
||||
case except_key: k = "except "; break;
|
||||
case check_key: k = "check "; break;
|
||||
// No default (so compiler warning/error on missing enum case).
|
||||
}
|
||||
try { throw; }
|
||||
@@ -130,10 +131,17 @@ namespace exception_ {
|
||||
template<failure_key Key>
|
||||
void default_from_handler(from) { default_handler<Key>(); }
|
||||
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREAD
|
||||
boost::mutex check_failure_mutex;
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::mutex entry_inv_failure_mutex;
|
||||
#endif
|
||||
failure_handler check_failure_handler = &default_handler<check_key>;
|
||||
from_failure_handler entry_inv_failure_handler =
|
||||
&default_from_handler<entry_inv_key>;
|
||||
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::mutex exit_inv_failure_mutex;
|
||||
#endif
|
||||
from_failure_handler exit_inv_failure_handler =
|
||||
&default_from_handler<exit_inv_key>;
|
||||
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::mutex pre_failure_mutex;
|
||||
@@ -146,16 +154,15 @@ namespace exception_ {
|
||||
from_failure_handler post_failure_handler = &default_from_handler<post_key>;
|
||||
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::mutex entry_inv_failure_mutex;
|
||||
boost::mutex except_failure_mutex;
|
||||
#endif
|
||||
from_failure_handler entry_inv_failure_handler =
|
||||
&default_from_handler<entry_inv_key>;
|
||||
from_failure_handler except_failure_handler =
|
||||
&default_from_handler<except_key>;
|
||||
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::mutex exit_inv_failure_mutex;
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREAD
|
||||
boost::mutex check_failure_mutex;
|
||||
#endif
|
||||
from_failure_handler exit_inv_failure_handler =
|
||||
&default_from_handler<exit_inv_key>;
|
||||
failure_handler check_failure_handler = &default_handler<check_key>;
|
||||
}
|
||||
|
||||
// IMPORTANT: Following func cannot be declared inline (on GCC, Clang, etc.) and
|
||||
@@ -209,6 +216,22 @@ void postcondition_failure(from where) /* can throw */ {
|
||||
exception_::post_failure_handler, where);
|
||||
}
|
||||
|
||||
from_failure_handler set_except_failure(from_failure_handler const& f)
|
||||
BOOST_NOEXCEPT_OR_NOTHROW {
|
||||
BOOST_CONTRACT_EXCEPTION_HANDLER_SET_(exception_::except_failure_mutex,
|
||||
from_failure_handler, exception_::except_failure_handler, f);
|
||||
}
|
||||
|
||||
from_failure_handler get_except_failure() BOOST_NOEXCEPT_OR_NOTHROW {
|
||||
BOOST_CONTRACT_EXCEPTION_HANDLER_GET_(exception_::except_failure_mutex,
|
||||
exception_::except_failure_handler);
|
||||
}
|
||||
|
||||
void except_failure(from where) /* can throw */ {
|
||||
BOOST_CONTRACT_EXCEPTION_HANDLER_(exception_::except_failure_mutex,
|
||||
exception_::except_failure_handler, where);
|
||||
}
|
||||
|
||||
from_failure_handler set_entry_invariant_failure(from_failure_handler const& f)
|
||||
BOOST_NOEXCEPT_OR_NOTHROW {
|
||||
BOOST_CONTRACT_EXCEPTION_HANDLER_SET_(exception_::entry_inv_failure_mutex,
|
||||
@@ -247,6 +270,14 @@ void set_invariant_failure(from_failure_handler const& f)
|
||||
set_exit_invariant_failure(f);
|
||||
}
|
||||
|
||||
void set_specification_failure(from_failure_handler const& f)
|
||||
BOOST_NOEXCEPT_OR_NOTHROW {
|
||||
set_precondition_failure(f);
|
||||
set_postcondition_failure(f);
|
||||
set_entry_invariant_failure(f);
|
||||
set_exit_invariant_failure(f);
|
||||
}
|
||||
|
||||
} } // namespace
|
||||
|
||||
#endif // #include guard
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
|
||||
#ifndef BOOST_CONTRACT_DETAIL_INLINED_DETAIL_CHECK_GUARD_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_INLINED_DETAIL_CHECK_GUARD_HPP_
|
||||
#ifndef BOOST_CONTRACT_DETAIL_INLINED_DETAIL_CHECKING_HPP_
|
||||
#define BOOST_CONTRACT_DETAIL_INLINED_DETAIL_CHECKING_HPP_
|
||||
|
||||
// Copyright (C) 2008-2016 Lorenzo Caminiti
|
||||
// Distributed under the Boost Software License, Version 1.0 (see accompanying
|
||||
// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
|
||||
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
#include <boost/thread/lock_guard.hpp>
|
||||
#endif
|
||||
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
check_guard::check_guard() {
|
||||
checking::checking() {
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::lock_guard<boost::mutex> lock(mutex_);
|
||||
#endif
|
||||
checking_ = true;
|
||||
}
|
||||
|
||||
check_guard::~check_guard() {
|
||||
checking::~checking() {
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::lock_guard<boost::mutex> lock(mutex_);
|
||||
#endif
|
||||
checking_ = false;
|
||||
}
|
||||
|
||||
bool check_guard::checking() {
|
||||
bool checking::already() {
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::lock_guard<boost::mutex> lock(mutex_);
|
||||
#endif
|
||||
return checking_;
|
||||
}
|
||||
|
||||
bool check_guard::checking_ = false;
|
||||
bool checking::checking_ = false;
|
||||
#ifndef BOOST_CONTRACT_DISABLE_THREADS
|
||||
boost::mutex check_guard::mutex_;
|
||||
boost::mutex checking::mutex_;
|
||||
#endif
|
||||
|
||||
} } } // namespace
|
||||
@@ -9,14 +9,16 @@
|
||||
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#include <boost/contract/detail/condition/check_pre_post_inv.hpp>
|
||||
#include <boost/contract/detail/condition/cond_with_inv.hpp>
|
||||
#include <boost/contract/detail/none.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/config.hpp>
|
||||
#include <exception>
|
||||
#endif
|
||||
@@ -24,51 +26,60 @@
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
// Ctor subcontracting impl via C++ obj construction mechanism.
|
||||
template<class C>
|
||||
class constructor :
|
||||
public check_pre_post_inv</* VR = */ none, C> { // Non-copyable base.
|
||||
template<class C> // Non-copyable base.
|
||||
class constructor : public cond_with_inv</* VR = */ none, C> {
|
||||
public:
|
||||
explicit constructor(C* obj) : check_pre_post_inv</* VR = */ none, C>(
|
||||
explicit constructor(C* obj) : cond_with_inv</* VR = */ none, C>(
|
||||
boost::contract::from_constructor, obj) {}
|
||||
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
void init() /* override */ {
|
||||
if(check_guard::checking()) return;
|
||||
if(checking::already()) return;
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
|
||||
{
|
||||
check_guard checking;
|
||||
checking k;
|
||||
this->check_entry_static_inv();
|
||||
// No object before ctor body so check only static inv at
|
||||
// entry. Ctor pre checked by constructor_precondition.
|
||||
}
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
this->copy_old();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
~constructor() BOOST_NOEXCEPT_IF(false) {
|
||||
this->assert_guarded();
|
||||
if(check_guard::checking()) return;
|
||||
check_guard checking;
|
||||
this->assert_initialized();
|
||||
if(checking::already()) return;
|
||||
checking k;
|
||||
|
||||
// If ctor body threw, no obj so check only static inv. Otherwise,
|
||||
// obj constructed so check static inv, non-static inv, and post.
|
||||
bool body_threw = std::uncaught_exception();
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
if(body_threw) this->check_exit_static_inv();
|
||||
else this->check_exit_all_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
if(!body_threw) this->check_post(none());
|
||||
#endif
|
||||
if(std::uncaught_exception()) {
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
this->check_exit_static_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
this->check_except();
|
||||
#endif
|
||||
} else {
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
this->check_exit_all_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
this->check_post(none());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -9,14 +9,16 @@
|
||||
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#include <boost/contract/detail/condition/check_pre_post_inv.hpp>
|
||||
#include <boost/contract/detail/condition/cond_with_inv.hpp>
|
||||
#include <boost/contract/detail/none.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/config.hpp>
|
||||
#include <exception>
|
||||
#endif
|
||||
@@ -24,40 +26,42 @@
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
// Dtor subcontracting impl via C++ obj destruction mechanism.
|
||||
template<class C>
|
||||
class destructor :
|
||||
public check_pre_post_inv</* VR = */ none, C> { // Non-copyable base.
|
||||
template<class C> // Non-copyable base.
|
||||
class destructor : public cond_with_inv</* VR = */ none, C> {
|
||||
public:
|
||||
explicit destructor(C* obj) : check_pre_post_inv</* VR = */ none, C>(
|
||||
explicit destructor(C* obj) : cond_with_inv</* VR = */ none, C>(
|
||||
boost::contract::from_destructor, obj) {}
|
||||
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
void init() /* override */ {
|
||||
if(check_guard::checking()) return;
|
||||
if(checking::already()) return;
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
|
||||
{
|
||||
check_guard checking;
|
||||
checking k;
|
||||
// Obj exists (before dtor body), check static and non- inv.
|
||||
this->check_entry_all_inv();
|
||||
// Dtor cannot have pre because it has no parameters.
|
||||
}
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
this->copy_old();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
~destructor() BOOST_NOEXCEPT_IF(false) {
|
||||
this->assert_guarded();
|
||||
if(check_guard::checking()) return;
|
||||
check_guard checking;
|
||||
this->assert_initialized();
|
||||
if(checking::already()) return;
|
||||
checking k;
|
||||
|
||||
// If dtor body threw, obj still exists so check subcontracted
|
||||
// static and non- inv (but no post because of throw). Otherwise,
|
||||
@@ -68,15 +72,21 @@ public:
|
||||
// language allows for that (even if in C++11 dtors declarations are
|
||||
// implicitly noexcept(true) unless specified otherwise) so this
|
||||
// library must handle such a case.
|
||||
bool body_threw = std::uncaught_exception();
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
if(body_threw) this->check_exit_all_inv();
|
||||
else this->check_exit_static_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
if(!body_threw) this->check_post(none());
|
||||
#endif
|
||||
if(std::uncaught_exception()) {
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
this->check_exit_all_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
this->check_except();
|
||||
#endif
|
||||
} else {
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
this->check_exit_static_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
this->check_post(none());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#include <boost/contract/detail/condition/check_pre_post.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
#include <boost/contract/detail/condition/cond_with_post.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/config.hpp>
|
||||
#include <exception>
|
||||
#endif
|
||||
@@ -22,39 +24,49 @@
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
// Used for free function, private and protected member functions.
|
||||
class function :
|
||||
public check_pre_post</* VR = */ none> { // Non-copyable base.
|
||||
class function : public cond_with_post</* VR = */ none> { // Non-copyable base.
|
||||
public:
|
||||
explicit function() : check_pre_post</* VR = */ none>(
|
||||
explicit function() : cond_with_post</* VR = */ none>(
|
||||
boost::contract::from_function) {}
|
||||
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
void init() /* override */ {
|
||||
if(check_guard::checking()) return;
|
||||
if(checking::already()) return;
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
{
|
||||
#ifndef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
|
||||
check_guard checking;
|
||||
checking k;
|
||||
#endif
|
||||
this->check_pre();
|
||||
}
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
this->copy_old();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
~function() BOOST_NOEXCEPT_IF(false) {
|
||||
this->assert_guarded();
|
||||
if(check_guard::checking()) return;
|
||||
check_guard checking;
|
||||
this->assert_initialized();
|
||||
if(checking::already()) return;
|
||||
checking k;
|
||||
|
||||
if(!std::uncaught_exception()) this->check_post(none());
|
||||
if(std::uncaught_exception()) {
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
this->check_except();
|
||||
#endif
|
||||
} else {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
this->check_post(none());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -10,19 +10,22 @@
|
||||
#include <boost/contract/core/virtual.hpp>
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#include <boost/contract/detail/condition/check_subcontracted_pre_post_inv.hpp>
|
||||
#include <boost/contract/detail/condition/cond_with_subcontracting.hpp>
|
||||
#include <boost/contract/detail/tvariadic.hpp>
|
||||
#include <boost/contract/core/virtual.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/config.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <exception>
|
||||
#endif
|
||||
|
||||
@@ -34,7 +37,7 @@ template<
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_TPARAMS_Z(1, BOOST_CONTRACT_MAX_ARGS, Args)
|
||||
>
|
||||
class public_function : // Non-copyable base.
|
||||
public check_subcontracted_pre_post_inv<
|
||||
public cond_with_subcontracting<
|
||||
O, VR, F, C
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(1, BOOST_CONTRACT_MAX_ARGS, Args)
|
||||
@@ -47,7 +50,7 @@ public:
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_FPARAMS_Z(1,
|
||||
BOOST_CONTRACT_MAX_ARGS, Args, &, args)
|
||||
) :
|
||||
check_subcontracted_pre_post_inv<
|
||||
cond_with_subcontracting<
|
||||
O, VR, F, C
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_COMMA(BOOST_CONTRACT_MAX_ARGS)
|
||||
BOOST_CONTRACT_DETAIL_TVARIADIC_ARGS_Z(1,
|
||||
@@ -61,32 +64,35 @@ public:
|
||||
{}
|
||||
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
void init() /* override */ {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
this->init_subcontracted_old();
|
||||
#endif
|
||||
if(!this->base_call()) {
|
||||
if(check_guard::checking()) return;
|
||||
{ // Acquire check guard.
|
||||
check_guard checking;
|
||||
if(checking::already()) return;
|
||||
{ // Acquire checking guard.
|
||||
checking k;
|
||||
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
|
||||
this->check_subcontracted_entry_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
#ifndef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
|
||||
#ifndef \
|
||||
BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
|
||||
this->check_subcontracted_pre();
|
||||
} // Release check guard.
|
||||
} // Release checking guard.
|
||||
#else
|
||||
} // Release check guard.
|
||||
} // Release checking guard.
|
||||
this->check_subcontracted_pre();
|
||||
#endif
|
||||
#else
|
||||
} // Release check guard.
|
||||
} // Release checking guard.
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
this->copy_subcontracted_old();
|
||||
#endif
|
||||
} else {
|
||||
@@ -96,38 +102,48 @@ private:
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
this->check_subcontracted_pre();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
this->copy_subcontracted_old();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
this->check_subcontracted_exit_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
if(!std::uncaught_exception()) {
|
||||
if(std::uncaught_exception()) {
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
this->check_subcontracted_except();
|
||||
#endif
|
||||
} else {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
this->check_subcontracted_post();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
~public_function() BOOST_NOEXCEPT_IF(false) {
|
||||
this->assert_guarded();
|
||||
this->assert_initialized();
|
||||
if(!this->base_call()) {
|
||||
if(check_guard::checking()) return;
|
||||
check_guard checking;
|
||||
if(checking::already()) return;
|
||||
checking k;
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
this->check_subcontracted_exit_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
if(!std::uncaught_exception()) {
|
||||
if(std::uncaught_exception()) {
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
this->check_subcontracted_except();
|
||||
#endif
|
||||
} else {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
this->check_subcontracted_post();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -9,78 +9,85 @@
|
||||
|
||||
#include <boost/contract/core/exception.hpp>
|
||||
#include <boost/contract/core/config.hpp>
|
||||
#include <boost/contract/detail/condition/check_pre_post_inv.hpp>
|
||||
#include <boost/contract/detail/condition/cond_with_inv.hpp>
|
||||
#include <boost/contract/detail/none.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(OOST_CONTRACT_NO_INVARIANTS)
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#endif
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
#include <boost/config.hpp>
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#include <exception>
|
||||
#endif
|
||||
|
||||
namespace boost { namespace contract { namespace detail {
|
||||
|
||||
// No subcontracting because static so no obj and no substitution principle.
|
||||
template<class C>
|
||||
class public_static_function :
|
||||
public check_pre_post_inv</* VR = */ none, C> { // Non-copyable base.
|
||||
template<class C> // Non-copyable base.
|
||||
class public_static_function : public cond_with_inv</* VR = */ none, C> {
|
||||
public:
|
||||
explicit public_static_function() :
|
||||
check_pre_post_inv</* VR = */ none, C>(boost::contract::from_function,
|
||||
/* obj = */ 0)
|
||||
{}
|
||||
explicit public_static_function() : cond_with_inv</* VR = */ none, C>(
|
||||
boost::contract::from_function, /* obj = */ 0) {}
|
||||
|
||||
private:
|
||||
#if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
void init() /* override */ {
|
||||
if(check_guard::checking()) return;
|
||||
if(checking::already()) return;
|
||||
#if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_PRECONDITIONS)
|
||||
{ // Acquire check guard.
|
||||
check_guard checking;
|
||||
{ // Acquire checking guard.
|
||||
checking k;
|
||||
#ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
|
||||
this->check_entry_static_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_PRECONDITIONS
|
||||
#ifndef BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
|
||||
#ifndef \
|
||||
BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION
|
||||
this->check_pre();
|
||||
} // Release check guard.
|
||||
} // Release checking guard.
|
||||
#else
|
||||
} // Release check guard.
|
||||
} // Release checking guard.
|
||||
this->check_pre();
|
||||
#endif
|
||||
#else
|
||||
} // Release check guard
|
||||
} // Release checking guard
|
||||
#endif
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_EXCEPTS)
|
||||
this->copy_old();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS)
|
||||
#if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
|
||||
!defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_EXCEPTS)
|
||||
~public_static_function() BOOST_NOEXCEPT_IF(false) {
|
||||
this->assert_guarded();
|
||||
if(check_guard::checking()) return;
|
||||
check_guard checking;
|
||||
this->assert_initialized();
|
||||
if(checking::already()) return;
|
||||
checking k;
|
||||
|
||||
#ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
|
||||
this->check_exit_static_inv();
|
||||
#endif
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
if(!std::uncaught_exception()) this->check_post(none());
|
||||
#endif
|
||||
if(std::uncaught_exception()) {
|
||||
#ifndef BOOST_CONTRACT_NO_EXCEPTS
|
||||
this->check_except();
|
||||
#endif
|
||||
} else {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
this->check_post(none());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ Program contracts for non-member, private, and protected functions.
|
||||
*/
|
||||
|
||||
#include <boost/contract/detail/all_core_headers.hpp>
|
||||
#if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
#include <boost/contract/detail/operation/function.hpp>
|
||||
#endif
|
||||
@@ -36,14 +36,14 @@ preconditions and postconditions.
|
||||
of the contracted function (otherwise this library will generate a
|
||||
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}).
|
||||
*/
|
||||
specify_precondition_old_postcondition<> function() {
|
||||
specify_precondition_old_postcondition_except<> function() {
|
||||
// Must #if also on ..._INVARIANTS here because specify_... is generic.
|
||||
#if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \
|
||||
#if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \
|
||||
!defined(BOOST_CONTRACT_NO_INVARIANTS)
|
||||
return specify_precondition_old_postcondition<>(
|
||||
return specify_precondition_old_postcondition_except<>(
|
||||
new boost::contract::detail::function());
|
||||
#else
|
||||
return specify_precondition_old_postcondition<>();
|
||||
return specify_precondition_old_postcondition_except<>();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ Facilities to support old values.
|
||||
*/
|
||||
|
||||
#include <boost/contract/detail/all_core_headers.hpp>
|
||||
#include <boost/contract/detail/check_guard.hpp>
|
||||
#include <boost/contract/detail/checking.hpp>
|
||||
#include <boost/contract/detail/operator_safe_bool.hpp>
|
||||
#include <boost/contract/detail/debug.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
@@ -382,7 +382,7 @@ private:
|
||||
typename Ptr::element_type>::value) {
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(!ptr_); // Non-copyable so no old...
|
||||
return Ptr(); // ...and return null.
|
||||
} else if(!v_ && boost::contract::detail::check_guard::checking()) {
|
||||
} else if(!v_ && boost::contract::detail::checking::already()) {
|
||||
// Return null shared ptr (see after if statement).
|
||||
} else if(!v_) {
|
||||
BOOST_CONTRACT_DETAIL_DEBUG(ptr_);
|
||||
@@ -491,7 +491,7 @@ being checked (see @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}).
|
||||
*/
|
||||
bool copy_old() {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
return !boost::contract::detail::check_guard::checking();
|
||||
return !boost::contract::detail::checking::already();
|
||||
#else
|
||||
return false; // Post checking disabled, so never copy old values.
|
||||
#endif
|
||||
@@ -510,7 +510,7 @@ being checked (see @RefMacro{BOOST_CONTRACT_NO_POSTCONDITIONS}).
|
||||
*/
|
||||
bool copy_old(virtual_* v) {
|
||||
#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
|
||||
if(!v) return !boost::contract::detail::check_guard::checking();
|
||||
if(!v) return !boost::contract::detail::checking::already();
|
||||
return v->action_ == boost::contract::virtual_::push_old_init ||
|
||||
v->action_ == boost::contract::virtual_::push_old_copy;
|
||||
#else
|
||||
|
||||
@@ -74,12 +74,12 @@ invariants.
|
||||
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}).
|
||||
*/
|
||||
template<class Class>
|
||||
specify_precondition_old_postcondition<> public_function() {
|
||||
specify_precondition_old_postcondition_except<> public_function() {
|
||||
#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
|
||||
return specify_precondition_old_postcondition<>(
|
||||
return specify_precondition_old_postcondition_except<>(
|
||||
new boost::contract::detail::public_static_function<Class>());
|
||||
#else
|
||||
return specify_precondition_old_postcondition<>();
|
||||
return specify_precondition_old_postcondition_except<>();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ invariants.
|
||||
run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}).
|
||||
*/
|
||||
template<class Class>
|
||||
specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
specify_precondition_old_postcondition_except<> public_function(Class* obj) {
|
||||
#ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS
|
||||
return specify_precondition_old_postcondition<>(
|
||||
return specify_precondition_old_postcondition_except<>(
|
||||
new boost::contract::detail::public_function<
|
||||
boost::contract::detail::none,
|
||||
boost::contract::detail::none,
|
||||
@@ -132,7 +132,7 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
)
|
||||
);
|
||||
#else
|
||||
return specify_precondition_old_postcondition<>();
|
||||
return specify_precondition_old_postcondition_except<>();
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
BOOST_PP_COMMA_IF(has_virtual_result) \
|
||||
class Class \
|
||||
> \
|
||||
specify_precondition_old_postcondition< \
|
||||
specify_precondition_old_postcondition_except< \
|
||||
BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)> \
|
||||
public_function( \
|
||||
virtual_* v \
|
||||
@@ -163,7 +163,7 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
) { \
|
||||
BOOST_PP_IIF(BOOST_CONTRACT_PUBLIC_FUNCTIONS_, \
|
||||
/* no F... so cannot enforce contracted F returns VirtualResult */ \
|
||||
return (specify_precondition_old_postcondition< \
|
||||
return (specify_precondition_old_postcondition_except< \
|
||||
BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)>( \
|
||||
new boost::contract::detail::public_function< \
|
||||
boost::contract::detail::none, \
|
||||
@@ -197,7 +197,7 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
) \
|
||||
)); \
|
||||
, \
|
||||
return specify_precondition_old_postcondition< \
|
||||
return specify_precondition_old_postcondition_except< \
|
||||
BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)>(); \
|
||||
) \
|
||||
}
|
||||
@@ -231,8 +231,8 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
@RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}).
|
||||
*/
|
||||
template<class Class>
|
||||
specify_precondition_old_postcondition<> public_function(virtual_* v,
|
||||
Class* obj);
|
||||
specify_precondition_old_postcondition_except<> public_function(
|
||||
virtual_* v, Class* obj);
|
||||
|
||||
/**
|
||||
Program contracts for virtual, not overriding public functions returning
|
||||
@@ -272,8 +272,8 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
@RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}).
|
||||
*/
|
||||
template<typename VirtualResult, class Class>
|
||||
specify_precondition_old_postcondition<VirtualResult> public_function(
|
||||
virtual_* v, VirtualResult& r, Class* obj);
|
||||
specify_precondition_old_postcondition_except<VirtualResult>
|
||||
public_function(virtual_* v, VirtualResult& r, Class* obj);
|
||||
#else
|
||||
BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_NO_OVERRIDE_(
|
||||
/* has_virtual_result = */ 0)
|
||||
@@ -319,7 +319,7 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
boost::contract::access::has_base_types<Class>::value, \
|
||||
"enclosing class missing 'base-types' typedef" \
|
||||
); \
|
||||
return (specify_precondition_old_postcondition< \
|
||||
return (specify_precondition_old_postcondition_except< \
|
||||
BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)>( \
|
||||
new boost::contract::detail::public_function< \
|
||||
Override, \
|
||||
@@ -351,7 +351,7 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
) \
|
||||
)); \
|
||||
, \
|
||||
return specify_precondition_old_postcondition< \
|
||||
return specify_precondition_old_postcondition_except< \
|
||||
BOOST_PP_EXPR_IIF(has_virtual_result, VirtualResult)>(); \
|
||||
) \
|
||||
}
|
||||
@@ -399,7 +399,7 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
@RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}).
|
||||
*/
|
||||
template<class Override, typename F, class Class, typename... Args>
|
||||
specify_precondition_old_postcondition<> public_function(
|
||||
specify_precondition_old_postcondition_except<> public_function(
|
||||
virtual_* v, F f, Class* obj, Args&... args);
|
||||
|
||||
/**
|
||||
@@ -452,8 +452,9 @@ specify_precondition_old_postcondition<> public_function(Class* obj) {
|
||||
*/
|
||||
template<class Override, typename VirtualResult, typename F, class Class,
|
||||
typename... Args>
|
||||
specify_precondition_old_postcondition<VirtualResult> public_function(
|
||||
virtual_* v, VirtualResult& r, F f, Class* obj, Args&... args);
|
||||
specify_precondition_old_postcondition_except<VirtualResult>
|
||||
public_function(virtual_* v, VirtualResult& r, F f, Class* obj,
|
||||
Args&... args);
|
||||
#elif BOOST_CONTRACT_DETAIL_TVARIADIC
|
||||
BOOST_CONTRACT_PUBLIC_FUNCTION_VIRTUAL_OVERRIDE_Z_(1, /* arity = */ ~,
|
||||
/* arity_compl = */ ~, /* has_virtual_result = */ 0)
|
||||
|
||||
Reference in New Issue
Block a user