From ff02b449ddeb948e258cf5007dc08a19430c44b5 Mon Sep 17 00:00:00 2001 From: Lorenzo Caminiti Date: Sun, 21 Aug 2016 09:54:10 -0700 Subject: [PATCH] added .except(...), renamed old_ptr_noncopyable to old_ptr_if_copyable, and renamed OLDOF to OLD --- doc/advanced_topics.qbk | 6 +- example/Jamfile.v2 | 10 +- example/cline90/calendar.cpp | 12 +- example/cline90/stack.cpp | 12 +- example/cline90/vector.hpp | 12 +- example/cline90/vstack.cpp | 38 +-- example/features/access.cpp | 8 +- example/features/base_types.cpp | 32 +- example/features/base_types_no_macros.cpp | 32 +- example/features/call_if_cxx14.cpp | 92 +++++ example/features/check.cpp | 2 +- example/features/condition_if.cpp | 2 +- example/features/function.cpp | 4 +- example/features/ifdef.cpp | 16 +- example/features/introduction.cpp | 8 +- example/features/move.cpp | 20 +- example/features/named_override.cpp | 8 +- example/features/no_lambdas.cpp | 10 +- example/features/no_lambdas.hpp | 6 +- example/features/no_lambdas_local_func.cpp | 16 +- example/features/old.cpp | 2 +- example/features/old_if_copyable.cpp | 2 +- example/features/old_no_macros.cpp | 2 +- example/features/optional_result.cpp | 2 +- example/features/overload.cpp | 26 +- example/features/private_protected.cpp | 8 +- .../features/private_protected_virtual.cpp | 16 +- .../private_protected_virtual_multi.cpp | 24 +- example/features/public.cpp | 25 +- example/features/pure_virtual_public.cpp | 10 +- example/features/separate_body.hpp | 10 +- example/features/static_public.cpp | 10 +- example/features/throw_on_failure.cpp | 28 +- example/features/union.cpp | 18 +- example/features/volatile.cpp | 12 +- example/meyer97/stack3.cpp | 27 +- example/meyer97/stack4.hpp | 26 +- example/mitchell02/counter/counter.hpp | 10 +- .../mitchell02/counter/decrement_button.hpp | 12 +- example/mitchell02/counter/push_button.hpp | 12 +- example/mitchell02/counter_main.cpp | 8 +- example/mitchell02/courier.cpp | 14 +- example/mitchell02/customer_manager.cpp | 16 +- example/mitchell02/dictionary.cpp | 18 +- example/mitchell02/name_list.cpp | 20 +- example/mitchell02/observer/observer.hpp | 8 +- example/mitchell02/observer/subject.hpp | 14 +- example/mitchell02/observer_main.cpp | 16 +- example/mitchell02/simple_queue.cpp | 30 +- example/mitchell02/stack.cpp | 20 +- example/n1962/circle.cpp | 8 +- example/n1962/equal.cpp | 4 +- example/n1962/factorial.cpp | 2 +- example/n1962/sqrt.cpp | 2 +- example/n1962/sum.cpp | 2 +- example/n1962/vector.cpp | 88 ++--- include/boost/contract.hpp | 16 +- include/boost/contract/assert.hpp | 2 +- include/boost/contract/check.hpp | 62 ++-- include/boost/contract/constructor.hpp | 16 +- include/boost/contract/core/access.hpp | 10 +- include/boost/contract/core/config.hpp | 36 +- include/boost/contract/core/exception.hpp | 14 + include/boost/contract/core/specify.hpp | 318 ++++++++++-------- include/boost/contract/core/virtual.hpp | 33 +- include/boost/contract/destructor.hpp | 10 +- include/boost/contract/detail/assert.hpp | 12 +- .../detail/{check_guard.hpp => checking.hpp} | 13 +- .../contract/detail/condition/check_base.hpp | 129 ------- .../contract/detail/condition/cond_base.hpp | 155 +++++++++ ...eck_pre_post_inv.hpp => cond_with_inv.hpp} | 31 +- ...{check_pre_post.hpp => cond_with_post.hpp} | 20 +- ...t_inv.hpp => cond_with_subcontracting.hpp} | 137 ++++---- include/boost/contract/detail/decl.hpp | 8 +- .../detail/inlined/core/exception.hpp | 59 +++- .../detail/{check_guard.hpp => checking.hpp} | 16 +- .../contract/detail/operation/constructor.hpp | 69 ++-- .../contract/detail/operation/destructor.hpp | 68 ++-- .../contract/detail/operation/function.hpp | 48 ++- .../detail/operation/public_function.hpp | 82 +++-- .../operation/public_static_function.hpp | 73 ++-- include/boost/contract/function.hpp | 10 +- include/boost/contract/old.hpp | 8 +- include/boost/contract/public_function.hpp | 37 +- src/contract.cpp | 2 +- test/Jamfile.v2 | 69 ++-- test/call_if/condition_if.cpp | 10 +- test/call_if/no_condition_if_error.cpp | 10 +- test/constructor/access.cpp | 6 +- test/constructor/body_throw.cpp | 33 +- test/constructor/contracts.cpp | 20 +- test/constructor/decl.hpp | 8 +- test/constructor/ifdef_contracts.cpp | 10 +- test/constructor/old_throw.cpp | 24 +- test/constructor/pre_error.cpp | 4 +- test/destructor/access.cpp | 6 +- test/destructor/body_throw.cpp | 27 +- test/destructor/contracts.cpp | 16 +- test/destructor/decl.hpp | 8 +- test/destructor/ifdef_contracts.cpp | 10 +- test/destructor/old_throw.cpp | 14 +- test/destructor/pre_error.cpp | 4 +- test/disable/lib_a_inlined.hpp | 12 +- test/disable/lib_b_inlined.hpp | 4 +- test/disable/lib_x.cpp | 8 +- test/disable/lib_xy.cpp | 4 +- test/disable/lib_y.cpp | 4 + test/disable/lib_y.hpp | 4 +- test/function/body_throw.cpp | 14 +- test/function/contracts.cpp | 8 +- test/function/decl.hpp | 6 +- test/function/ifdef_contracts.cpp | 6 +- test/function/old_throw.cpp | 10 +- test/invariant/decl.hpp | 28 +- test/invariant/mutable.hpp | 4 +- test/invariant/static.hpp | 4 +- test/invariant/static_const.hpp | 4 +- test/invariant/static_cv.hpp | 4 +- test/invariant/static_mutable.hpp | 4 +- test/invariant/static_volatile.hpp | 4 +- test/invariant/volatile.hpp | 4 +- test/old/auto.cpp | 6 +- test/old/{noncopyable.cpp => if_copyable.cpp} | 18 +- ...pyable_error.cpp => if_copyable_error.cpp} | 6 +- test/old/no_equal.cpp | 10 +- test/old/no_equal_error.cpp | 10 +- test/old/no_macros.hpp | 10 +- ...copyable.cpp => no_macros_if_copyable.cpp} | 2 +- ....cpp => no_make_old_if_copyable_error.cpp} | 2 +- test/public_function/access.cpp | 6 +- test/public_function/body_throw.cpp | 38 ++- test/public_function/contracts.hpp | 20 +- test/public_function/decl.hpp | 14 +- .../public_function}/friend.cpp | 8 +- test/public_function/ifdef_contracts.cpp | 10 +- test/public_function/max_args.hpp | 6 +- test/public_function/max_bases.cpp | 6 +- test/public_function/old_throw.cpp | 8 +- test/public_function/overload.hpp | 30 +- test/public_function/override.hpp | 6 +- test/public_function/protected.cpp | 6 +- test/public_function/protected_error.cpp | 6 +- test/public_function/static.cpp | 6 +- test/public_function/static_body_throw.cpp | 4 +- test/public_function/static_no_contracts.cpp | 6 +- test/public_function/static_old_throw.cpp | 4 +- test/public_function/virtual_access.cpp | 50 +-- test/public_function/virtual_access_multi.cpp | 74 ++-- test/public_function/virtual_sparse.cpp | 38 +-- test/result/mixed_optional.hpp | 22 +- test/result/type_mismatch_error.cpp | 6 +- .../{no_guard.cpp => missing_check_decl.cpp} | 10 +- test/specify/nothing.cpp | 4 +- test/specify/old.cpp | 4 +- test/specify/old_post.cpp | 4 +- test/specify/old_pre_error.cpp | 4 +- test/specify/post.cpp | 4 +- test/specify/post_old_error.cpp | 4 +- test/specify/post_pre_error.cpp | 4 +- test/specify/pre.cpp | 4 +- test/specify/pre_old.cpp | 4 +- test/specify/pre_old_post.cpp | 4 +- test/specify/pre_post.cpp | 4 +- 163 files changed, 1808 insertions(+), 1491 deletions(-) create mode 100644 example/features/call_if_cxx14.cpp rename include/boost/contract/detail/{check_guard.hpp => checking.hpp} (80%) delete mode 100644 include/boost/contract/detail/condition/check_base.hpp create mode 100644 include/boost/contract/detail/condition/cond_base.hpp rename include/boost/contract/detail/condition/{check_pre_post_inv.hpp => cond_with_inv.hpp} (90%) rename include/boost/contract/detail/condition/{check_pre_post.hpp => cond_with_post.hpp} (79%) rename include/boost/contract/detail/condition/{check_subcontracted_pre_post_inv.hpp => cond_with_subcontracting.hpp} (79%) rename include/boost/contract/detail/inlined/detail/{check_guard.hpp => checking.hpp} (72%) rename test/old/{noncopyable.cpp => if_copyable.cpp} (87%) rename test/old/{noncopyable_error.cpp => if_copyable_error.cpp} (90%) rename test/old/{no_macros_noncopyable.cpp => no_macros_if_copyable.cpp} (96%) rename test/old/{no_make_old_noncopyable_error.cpp => no_make_old_if_copyable_error.cpp} (96%) rename {example/features => test/public_function}/friend.cpp (83%) rename test/specify/{no_guard.cpp => missing_check_decl.cpp} (78%) diff --git a/doc/advanced_topics.qbk b/doc/advanced_topics.qbk index 5e65afd..b747a6f 100644 --- a/doc/advanced_topics.qbk +++ b/doc/advanced_topics.qbk @@ -407,10 +407,10 @@ The [funcref boost::contract::check_if_c], [funcref boost::contract::call_if_c], The [funcref boost::contract::call_if] function template is a general facility and its use is not limited to programming contracts. In fact, [funcref boost::contract::call_if] can be used together with C++14 generic lambdas to program statements similar to the `static if` proposal (at least at function scope, see also [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3613.pdf N3613]). -For example, consider the following implementation of `std::advance` that uses `static if`-like statements programmed via [funcref boost::contract::call_if] (see also [@../../test/call_if/advance_cxx14.cpp =advance_cxx14.cpp=]): +For example, consider the following implementation of `std::advance` that uses `static if`-like statements programmed via [funcref boost::contract::call_if] (see also [@../../example/features/call_if_cxx14.cpp =call_if_cxx14.cpp=]): -[import ../test/call_if/advance_cxx14.cpp] -[advance_cxx14] +[import ../example/features/call_if_cxx14.cpp] +[call_if_cxx14] This implementation is much more concise, easy to read and maintain than the usual implementation of `std::advance` that uses tag dispatching. [footnote diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index bb1b906..3f85478 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -17,7 +17,6 @@ test-suite features : [ subdir-run features : private_protected ] [ subdir-run features : private_protected_virtual ] [ subdir-run features : private_protected_virtual_multi ] - [ subdir-run features : friend ] [ subdir-run features : check ] [ subdir-run features : old ] @@ -28,8 +27,8 @@ test-suite features : [ subdir-run features : move ] [ subdir-run features : union ] [ subdir-run features : volatile ] - [ subdir-run features : old_noncopyable ] - [ subdir-run features : check_if ] + [ subdir-run features : old_if_copyable ] + [ subdir-run features : condition_if ] [ subdir-run features : access ] [ subdir-run features : separate_body ] [ subdir-run features : throw_on_failure ] @@ -39,6 +38,11 @@ test-suite features : [ subdir-run features : no_lambdas ] [ subdir-run features : no_lambdas_local_func ] ; +test-suite features-cxx14 : # Requires C++14. + [ subdir-run features : call_if_cxx14 : + clang:-std=c++1y ] +; +explicit features-cxx14 ; test-suite n1962 : [ subdir-run n1962 : vector ] diff --git a/example/cline90/calendar.cpp b/example/cline90/calendar.cpp index ca17a88..6cecfd5 100644 --- a/example/cline90/calendar.cpp +++ b/example/cline90/calendar.cpp @@ -20,7 +20,7 @@ class calendar { public: calendar() : month_(1), date_(31) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(month() == 1); BOOST_CONTRACT_ASSERT(date() == 31); @@ -30,23 +30,23 @@ public: virtual ~calendar() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } int month() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return month_; } int date() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return date_; } void reset(int new_month) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(new_month >= 1); BOOST_CONTRACT_ASSERT(new_month <= 12); @@ -62,7 +62,7 @@ public: private: static int days_in(int month) { int result; - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(month >= 1); BOOST_CONTRACT_ASSERT(month <= 12); diff --git a/example/cline90/stack.cpp b/example/cline90/stack.cpp index 25ac821..8946361 100644 --- a/example/cline90/stack.cpp +++ b/example/cline90/stack.cpp @@ -25,7 +25,7 @@ public: }), data_(new T[capacity]), capacity_(capacity), size_(0) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(empty()); BOOST_CONTRACT_ASSERT(full() == (capacity == 0)); @@ -36,22 +36,22 @@ public: } virtual ~stack() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); delete[] data_; } bool empty() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size_ == 0; } bool full() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size_ == capacity_; } void push(T const& value) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!full()); }) @@ -64,7 +64,7 @@ public: } T pop() { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) diff --git a/example/cline90/vector.hpp b/example/cline90/vector.hpp index b5497bb..19b52b6 100644 --- a/example/cline90/vector.hpp +++ b/example/cline90/vector.hpp @@ -32,7 +32,7 @@ public: data_(new T[count]), size_(count) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == count); }) @@ -42,17 +42,17 @@ public: } virtual ~vector() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); delete[] data_; } int size() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size_; // Non-negative result already checked by invariant. } void resize(int count) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(count >= 0); }) @@ -69,7 +69,7 @@ public: } T& operator[](int index) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(index >= 0); BOOST_CONTRACT_ASSERT(index < size()); @@ -80,7 +80,7 @@ public: } T const& operator[](int index) const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(index >= 0); BOOST_CONTRACT_ASSERT(index < size()); diff --git a/example/cline90/vstack.cpp b/example/cline90/vstack.cpp index 7b286e7..dd85564 100644 --- a/example/cline90/vstack.cpp +++ b/example/cline90/vstack.cpp @@ -15,19 +15,19 @@ template class abstract_stack { public: abstract_stack() { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) // Postcondition: empty() (but it cannot be checked here to avoid // calling pure virtual function length() during construction). ; } virtual ~abstract_stack() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } bool full() const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(result == (length() == capacity())); }) @@ -38,7 +38,7 @@ public: bool empty() const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(result = (length() == 0)); }) @@ -61,7 +61,7 @@ public: template int abstract_stack::length(boost::contract::virtual_* v) const { int result; - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .postcondition([&] (int const& result) { BOOST_CONTRACT_ASSERT(result >= 0); }) @@ -73,7 +73,7 @@ int abstract_stack::length(boost::contract::virtual_* v) const { template int abstract_stack::capacity(boost::contract::virtual_* v) const { int result; - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .postcondition([&] (int const& result) { BOOST_CONTRACT_ASSERT(result >= 0); }) @@ -85,7 +85,7 @@ int abstract_stack::capacity(boost::contract::virtual_* v) const { template T const& abstract_stack::item(boost::contract::virtual_* v) const { boost::optional result; - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) @@ -96,7 +96,7 @@ T const& abstract_stack::item(boost::contract::virtual_* v) const { template void abstract_stack::push(T const& value, boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(!full()); }) @@ -110,8 +110,8 @@ void abstract_stack::push(T const& value, boost::contract::virtual_* v) { template T const& abstract_stack::pop(boost::contract::virtual_* v) { boost::optional result; - boost::contract::old_ptr old_item = BOOST_CONTRACT_OLDOF(v, item()); - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::old_ptr old_item = BOOST_CONTRACT_OLD(v, item()); + boost::contract::check c = boost::contract::public_function(v, result, this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) @@ -126,7 +126,7 @@ T const& abstract_stack::pop(boost::contract::virtual_* v) { template void abstract_stack::clear(boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .postcondition([&] { BOOST_CONTRACT_ASSERT(empty()); }) @@ -158,7 +158,7 @@ public: vect_(count), // OK, executed after precondition so count >= 0. len_(0) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(length() == 0); BOOST_CONTRACT_ASSERT(capacity() == count); @@ -167,14 +167,14 @@ public: } virtual ~vstack() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } // Inherited from abstract_stack. virtual int length(boost::contract::virtual_* v = 0) const /* override */ { int result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_length>(v, result, &vstack::length, this); return result = len_; } @@ -182,7 +182,7 @@ public: virtual int capacity(boost::contract::virtual_* v = 0) const /* override */ { int result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_capacity>(v, result, &vstack::capacity, this); return result = vect_.size(); } @@ -190,27 +190,27 @@ public: virtual T const& item(boost::contract::virtual_* v = 0) const /* override */ { boost::optional result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_item>(v, result, &vstack::item, this); return *(result = vect_[len_ - 1]); } virtual void push(T const& value, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_push>(v, &vstack::push, this, value); vect_[len_++] = value; } virtual T const& pop(boost::contract::virtual_* v = 0) /* override */ { boost::optional result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_pop>(v, result, &vstack::pop, this); return *(result = vect_[--len_]); } virtual void clear(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_clear>(v, &vstack::clear, this); len_ = 0; } diff --git a/example/features/access.cpp b/example/features/access.cpp index 2e0b2b8..d4b3ac0 100644 --- a/example/features/access.cpp +++ b/example/features/access.cpp @@ -29,8 +29,8 @@ protected: template void pushable::push_back(T const& value, boost::contract::virtual_* v) { boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - boost::contract::guard c = boost::contract::public_function(v, this) + BOOST_CONTRACT_OLD(v, capacity()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(capacity() < max_size()); }) @@ -63,8 +63,8 @@ public: void push_back(T const& value, boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, size()); + boost::contract::check c = boost::contract::public_function< override_push_back>(v, &vector::push_back, this, value) .precondition([&] { BOOST_CONTRACT_ASSERT(size() < max_size()); diff --git a/example/features/base_types.cpp b/example/features/base_types.cpp index 464d0d7..8987baf 100644 --- a/example/features/base_types.cpp +++ b/example/features/base_types.cpp @@ -24,8 +24,8 @@ protected: template void pushable::push_back(T x, boost::contract::virtual_* v) { boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - boost::contract::guard c = boost::contract::public_function(v, this) + BOOST_CONTRACT_OLD(v, capacity()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(capacity() < max_size()); }) @@ -52,7 +52,7 @@ public: BOOST_CONTRACT_ASSERT(from <= to); }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == (to - from + 1)); }) @@ -62,17 +62,17 @@ public: } virtual ~unique_chars() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } int size() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.size(); } bool find(char x) const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { if(size() == 0) BOOST_CONTRACT_ASSERT(!result); }) @@ -83,10 +83,9 @@ public: virtual void push_back(char x, boost::contract::virtual_* v = 0) { boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(x)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::guard c = boost::contract::public_function(v, this) + BOOST_CONTRACT_OLD(v, find(x)); + boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(v, size()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(!find(x)); }) @@ -132,7 +131,7 @@ public: } chars(char from, char to) : unique_chars(from, to) { - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } chars(char const* const c_str) : @@ -140,17 +139,16 @@ public: BOOST_CONTRACT_ASSERT(c_str[0] != '\0'); }) { - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); for(int i = 0; c_str[i] != '\0'; ++i) push_back(c_str[i]); } void push_back(char x, boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(x)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, find(x)); + boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(v, size()); + boost::contract::check c = boost::contract::public_function< override_push_back>(v, &chars::push_back, this, x) .precondition([&] { BOOST_CONTRACT_ASSERT(find(x)); @@ -165,7 +163,7 @@ public: BOOST_CONTRACT_OVERRIDE(push_back); bool empty() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size() == 0; } diff --git a/example/features/base_types_no_macros.cpp b/example/features/base_types_no_macros.cpp index 8ad90f5..264c6b8 100644 --- a/example/features/base_types_no_macros.cpp +++ b/example/features/base_types_no_macros.cpp @@ -24,8 +24,8 @@ protected: template void pushable::push_back(T x, boost::contract::virtual_* v) { boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - boost::contract::guard c = boost::contract::public_function(v, this) + BOOST_CONTRACT_OLD(v, capacity()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(capacity() < max_size()); }) @@ -52,7 +52,7 @@ public: BOOST_CONTRACT_ASSERT(from <= to); }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == (to - from + 1)); }) @@ -62,17 +62,17 @@ public: } virtual ~unique_chars() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } int size() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.size(); } bool find(char x) const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { if(size() == 0) BOOST_CONTRACT_ASSERT(!result); }) @@ -83,10 +83,9 @@ public: virtual void push_back(char x, boost::contract::virtual_* v = 0) { boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(x)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::guard c = boost::contract::public_function(v, this) + BOOST_CONTRACT_OLD(v, find(x)); + boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(v, size()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(!find(x)); }) @@ -132,7 +131,7 @@ public: } chars(char from, char to) : unique_chars(from, to) { - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } chars(char const* const c_str) : @@ -140,17 +139,16 @@ public: BOOST_CONTRACT_ASSERT(c_str[0] != '\0'); }) { - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); for(int i = 0; c_str[i] != '\0'; ++i) push_back(c_str[i]); } void push_back(char x, boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(x)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, find(x)); + boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(v, size()); + boost::contract::check c = boost::contract::public_function< override_push_back>(v, &chars::push_back, this, x) .precondition([&] { BOOST_CONTRACT_ASSERT(find(x)); @@ -165,7 +163,7 @@ public: BOOST_CONTRACT_OVERRIDE(push_back); bool empty() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size() == 0; } diff --git a/example/features/call_if_cxx14.cpp b/example/features/call_if_cxx14.cpp new file mode 100644 index 0000000..09d1cbb --- /dev/null +++ b/example/features/call_if_cxx14.cpp @@ -0,0 +1,92 @@ + +// 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 +#include +#include +#include // std::bind for generic lambdas. +#include +#include +#include + +template +struct is_random_access_iterator : std::is_same< + typename std::iterator_traits::iterator_category, + std::random_access_iterator_tag +> {}; + +template +struct is_bidirectional_iterator : std::is_same< + typename std::iterator_traits::iterator_category, + std::bidirectional_iterator_tag +> {}; + +template +struct is_input_iterator : std::is_same< + typename std::iterator_traits::iterator_category, + std::input_iterator_tag +> {}; + +//[call_if_cxx14 +template +void myadvance(Iter& i, Dist n) { + Iter *p = &i; // So captures change actual pointed iterator value. + boost::contract::call_if >( + std::bind([] (auto p, auto n) { // C++14 generic lambda. + *p += n; + }, p, n) + ).template else_if >( + std::bind([] (auto p, auto n) { + if(n >= 0) while(n--) ++*p; + else while(n++) --*p; + }, p, n) + ).template else_if >( + std::bind([] (auto p, auto n) { + while(n--) ++*p; + }, p, n) + ).else_( + std::bind([] (auto false_) { + static_assert(false_, "requires at least input iterator"); + }, std::false_type()) // Use constexpr value. + ); +} +//] + +struct x {}; // Test not an iterator (static_assert failure in else_ above). + +namespace std { + template<> + struct iterator_traits { + typedef void iterator_category; + }; +} + +int main() { + std::vector v; + v.push_back('a'); + v.push_back('b'); + v.push_back('c'); + v.push_back('d'); + std::vector::iterator r = v.begin(); // Random iterator. + myadvance(r, 1); + assert(*r == 'b'); + + std::list l(v.begin(), v.end()); + std::list::iterator b = l.begin(); // Bidirectional iterator. + myadvance(b, 2); + assert(*b == 'c'); + + std::istringstream s("a b c d"); + std::istream_iterator i(s); + myadvance(i, 3); + assert(*i == 'd'); + + // x j; + // myadvance(j, 0); // Error (correctly because x not even input iter). + + return 0; +} + diff --git a/example/features/check.cpp b/example/features/check.cpp index b5501ad..7e62a5b 100644 --- a/example/features/check.cpp +++ b/example/features/check.cpp @@ -32,7 +32,7 @@ int gcd(int const a, int const b) { //[check_macro while(x != y) { - BOOST_CONTRACT_CHECK(x > 0); // Body checks with macro (preferred). + BOOST_CONTRACT_CHECK(x > 0); // Body checks with macros (preferred). BOOST_CONTRACT_CHECK(y > 0); if(x > y) x = x - y; diff --git a/example/features/condition_if.cpp b/example/features/condition_if.cpp index 873fc04..046ee11 100644 --- a/example/features/condition_if.cpp +++ b/example/features/condition_if.cpp @@ -15,7 +15,7 @@ template class vector { public: void push_back(T const& value) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Instead of `ASSERT(back() == value)` for T without `==`. BOOST_CONTRACT_ASSERT( diff --git a/example/features/function.cpp b/example/features/function.cpp index 4d444b6..751d420 100644 --- a/example/features/function.cpp +++ b/example/features/function.cpp @@ -12,8 +12,8 @@ int inc(int& x) { int result; - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - boost::contract::guard c = boost::contract::function() + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(x); + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(x < std::numeric_limits::max()); }) diff --git a/example/features/ifdef.cpp b/example/features/ifdef.cpp index ad5412c..e8a54b4 100644 --- a/example/features/ifdef.cpp +++ b/example/features/ifdef.cpp @@ -16,10 +16,10 @@ int inc(int& x) { int result; #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(x); #endif #ifndef BOOST_CONTRACT_NO_FUNCTIONS - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() #ifndef BOOST_CONTRACT_NO_PRECONDITIONS .precondition([&] { BOOST_CONTRACT_ASSERT(x < std::numeric_limits::max()); @@ -72,10 +72,10 @@ void pushable::push_back( ) { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); + BOOST_CONTRACT_OLD(v, capacity()); #endif #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) #ifndef BOOST_CONTRACT_NO_PRECONDITIONS .precondition([&] { BOOST_CONTRACT_ASSERT(capacity() < max_size()); @@ -127,7 +127,7 @@ public: vect_(to - from + 1) { #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS .postcondition([&] { BOOST_CONTRACT_ASSERT(int(size()) == (to - from + 1)); @@ -142,7 +142,7 @@ public: virtual ~integers() { #ifndef BOOST_CONTRACT_NO_DESTRUCTORS // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); #endif } @@ -156,7 +156,7 @@ public: boost::contract::old_ptr old_size; #endif #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_push_back>(v, &integers::push_back, this, x) #ifndef BOOST_CONTRACT_NO_PRECONDITIONS .precondition([&] { @@ -165,7 +165,7 @@ public: #endif #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS .old([&] { - old_size = BOOST_CONTRACT_OLDOF(v, size()); + old_size = BOOST_CONTRACT_OLD(v, size()); }) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == *old_size + 1); diff --git a/example/features/introduction.cpp b/example/features/introduction.cpp index 30cc9eb..9eee824 100644 --- a/example/features/introduction.cpp +++ b/example/features/introduction.cpp @@ -28,8 +28,8 @@ public: virtual void push_back(T const& value, boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); // Old values. - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, size()); // Old values. + boost::contract::check c = boost::contract::public_function< override_push_back>(v, &vector::push_back, this, value) .precondition([&] { // Checked in OR with base preconditions. BOOST_CONTRACT_ASSERT(size() < max_size()); // Line 35. @@ -71,8 +71,8 @@ protected: template // Contract for pure virtual function. void pushable::push_back(T const& value, boost::contract::virtual_* v) { boost::contract::old_ptr old_capacity = - BOOST_CONTRACT_OLDOF(v, capacity()); - boost::contract::guard c = boost::contract::public_function(v, this) + BOOST_CONTRACT_OLD(v, capacity()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(capacity() < max_size()); }) diff --git a/example/features/move.cpp b/example/features/move.cpp index 4ad93ed..82c96bb 100644 --- a/example/features/move.cpp +++ b/example/features/move.cpp @@ -28,7 +28,7 @@ public: index_(start), moved_(false) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(!moved()); }) @@ -37,7 +37,7 @@ public: ~circular_buffer() { // Moved-from can always be destroyed (so no pre `!moved()` here). - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } // Copy constructor. @@ -46,7 +46,7 @@ public: BOOST_CONTRACT_ASSERT(!other.moved()); }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(!moved()); }) @@ -58,7 +58,7 @@ public: // Copy assignment. circular_buffer& operator=(circular_buffer const& other) { // Moved-from can be (copy) assigned (so no pre `!moved()` here). - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!other.moved()); }) @@ -76,7 +76,7 @@ public: BOOST_CONTRACT_ASSERT(!other.moved()); }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(!moved()); BOOST_CONTRACT_ASSERT(other.moved()); @@ -89,7 +89,7 @@ public: // Move assignment. circular_buffer& operator=(circular_buffer&& other) { // Moved-from can be (move) assigned (so no pre `!moved()` here). - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!other.moved()); }) @@ -103,7 +103,7 @@ public: } char read() { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!moved()); }) @@ -115,7 +115,7 @@ public: } bool moved() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return moved_; } @@ -144,12 +144,12 @@ private: public: unsigned index() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return index_; } unsigned size() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return data_.size(); } }; diff --git a/example/features/named_override.cpp b/example/features/named_override.cpp index 663e1d5..806c45c 100644 --- a/example/features/named_override.cpp +++ b/example/features/named_override.cpp @@ -18,7 +18,7 @@ public: template void generic_unary_pack::_1(T const& value, boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { // Derived concrete classes will enforce preconditions. BOOST_CONTRACT_ASSERT(false); @@ -33,7 +33,7 @@ void generic_unary_pack::_1(T const& value, boost::contract::virtual_* v) { template T generic_unary_pack::_1(boost::contract::virtual_* v) const { boost::optional result; // Do not assume T has default constructor. - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .postcondition([&] (boost::optional const& result) { BOOST_CONTRACT_ASSERT(*result == _1()); }) @@ -59,7 +59,7 @@ public: virtual void _1(T const& value, boost::contract::virtual_* v = 0) /* override */ { // Use `override1` type generated by NAMED_OVERRIDE macro above. - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, static_cast(&positive_unary_pack::_1), @@ -78,7 +78,7 @@ public: virtual T _1(boost::contract::virtual_* v = 0) const /* override */ { T result; // Class default constructor already used T's default ctor. - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, static_cast::array(unsigned count) : values_(new T[MaxSize]) // Member initializations can be here. { boost::contract::old_ptr old_instances; - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old(boost::bind(&array::constructor_old, boost::ref(old_instances))) .postcondition(boost::bind(&array::constructor_postcondition, this, boost::cref(count), boost::cref(old_instances))) @@ -30,7 +30,7 @@ array::array(unsigned count) : template array::~array() { boost::contract::old_ptr old_instances; - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .old(boost::bind(&array::destructor_old, this, boost::ref(old_instances))) .postcondition(boost::bind(&array::destructor_postcondition, @@ -45,7 +45,7 @@ template void array::push_back(T const& value, boost::contract::virtual_* v) { boost::contract::old_ptr old_size; - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition(boost::bind(&array::push_back_precondition, this)) .old(boost::bind(&array::push_back_old, this, boost::cref(v), boost::ref(old_size))) @@ -59,14 +59,14 @@ void array::push_back(T const& value, template unsigned array::size() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size_; } template int array::instances() { // Check static invariants. - boost::contract::guard c = boost::contract::public_function(); + boost::contract::check c = boost::contract::public_function(); return instances_; } diff --git a/example/features/no_lambdas.hpp b/example/features/no_lambdas.hpp index bb381c1..dfdd5c3 100644 --- a/example/features/no_lambdas.hpp +++ b/example/features/no_lambdas.hpp @@ -28,7 +28,7 @@ public: } static void constructor_old(boost::contract::old_ptr& old_instances) { - old_instances = BOOST_CONTRACT_OLDOF(instances()); + old_instances = BOOST_CONTRACT_OLD(instances()); } void constructor_postcondition(unsigned const count, boost::contract::old_ptr const old_instances) const { @@ -39,7 +39,7 @@ public: virtual ~array(); void destructor_old(boost::contract::old_ptr& old_instances) const { - old_instances = BOOST_CONTRACT_OLDOF(instances()); + old_instances = BOOST_CONTRACT_OLD(instances()); } static void destructor_postcondition(boost::contract::old_ptr const old_instances) { @@ -52,7 +52,7 @@ public: } void push_back_old(boost::contract::virtual_* v, boost::contract::old_ptr& old_size) const { - old_size = BOOST_CONTRACT_OLDOF(v, size()); + old_size = BOOST_CONTRACT_OLD(v, size()); } void push_back_postcondition( boost::contract::old_ptr const old_size) const { diff --git a/example/features/no_lambdas_local_func.cpp b/example/features/no_lambdas_local_func.cpp index 68ae957..c9bdeee 100644 --- a/example/features/no_lambdas_local_func.cpp +++ b/example/features/no_lambdas_local_func.cpp @@ -33,14 +33,14 @@ public: { boost::contract::old_ptr old_instances; void BOOST_LOCAL_FUNCTION_TPL(bind& old_instances) { - old_instances = BOOST_CONTRACT_OLDOF(array::instances()); + old_instances = BOOST_CONTRACT_OLD(array::instances()); } BOOST_LOCAL_FUNCTION_NAME_TPL(old) void BOOST_LOCAL_FUNCTION_TPL(const bind this_, const bind& count, const bind& old_instances) { BOOST_CONTRACT_ASSERT(this_->size() == count); BOOST_CONTRACT_ASSERT(this_->instances() == *old_instances + 1); } BOOST_LOCAL_FUNCTION_NAME_TPL(post) - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old(old).postcondition(post); for(unsigned i = 0; i < count; ++i) values_[i] = T(); @@ -51,12 +51,12 @@ public: virtual ~array() { boost::contract::old_ptr old_instances; void BOOST_LOCAL_FUNCTION_TPL(const bind this_, bind& old_instances) { - old_instances = BOOST_CONTRACT_OLDOF(this_->instances()); + old_instances = BOOST_CONTRACT_OLD(this_->instances()); } BOOST_LOCAL_FUNCTION_NAME_TPL(old) void BOOST_LOCAL_FUNCTION_TPL(const bind& old_instances) { BOOST_CONTRACT_ASSERT(array::instances() == *old_instances - 1); } BOOST_LOCAL_FUNCTION_NAME_TPL(post) - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .old(old).postcondition(post); delete[] values_; @@ -70,12 +70,12 @@ public: } BOOST_LOCAL_FUNCTION_NAME_TPL(pre) void BOOST_LOCAL_FUNCTION_TPL(const bind v, const bind this_, bind& old_size) { - old_size = BOOST_CONTRACT_OLDOF(v, this_->size()); + old_size = BOOST_CONTRACT_OLD(v, this_->size()); } BOOST_LOCAL_FUNCTION_NAME_TPL(old) void BOOST_LOCAL_FUNCTION_TPL(const bind this_, const bind& old_size) { BOOST_CONTRACT_ASSERT(this_->size() == *old_size + 1); } BOOST_LOCAL_FUNCTION_NAME_TPL(post) - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition(pre).old(old).postcondition(post); values_[size_++] = value; @@ -83,13 +83,13 @@ public: unsigned size() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size_; } static int instances() { // Check static invariants. - boost::contract::guard c = boost::contract::public_function(); + boost::contract::check c = boost::contract::public_function(); return instances_; } diff --git a/example/features/old.cpp b/example/features/old.cpp index 1ccfc80..c37e3e2 100644 --- a/example/features/old.cpp +++ b/example/features/old.cpp @@ -13,7 +13,7 @@ char replace(std::string& s, std::size_t index, char x) { char result; boost::contract::old_ptr old_y; // But old value copied later... - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(index < s.size()); }) diff --git a/example/features/old_if_copyable.cpp b/example/features/old_if_copyable.cpp index 5fe3c3f..5c3c8f8 100644 --- a/example/features/old_if_copyable.cpp +++ b/example/features/old_if_copyable.cpp @@ -13,7 +13,7 @@ void accumulate(T& total, T const& x) { // No compiler error if T has no copy constructor... boost::contract::old_ptr_if_copyable old_total = BOOST_CONTRACT_OLD(total); - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .postcondition([&] { // ...but old value null if T has no copy constructor. if(old_total) BOOST_CONTRACT_ASSERT(total == *old_total + x); diff --git a/example/features/old_no_macros.cpp b/example/features/old_no_macros.cpp index 5a6bd00..7099004 100644 --- a/example/features/old_no_macros.cpp +++ b/example/features/old_no_macros.cpp @@ -19,7 +19,7 @@ public: size() : boost::contract::null_old()) ; - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == *old_size + 1); }) diff --git a/example/features/optional_result.cpp b/example/features/optional_result.cpp index 5dfee1e..ad485b5 100644 --- a/example/features/optional_result.cpp +++ b/example/features/optional_result.cpp @@ -19,7 +19,7 @@ struct surface { surface square_surface(int edge) { boost::optional result; // No default constructor so use optional. - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(edge > 0); }) diff --git a/example/features/overload.cpp b/example/features/overload.cpp index bc497d7..a1936a9 100644 --- a/example/features/overload.cpp +++ b/example/features/overload.cpp @@ -25,7 +25,7 @@ public: std::string lines::str(boost::contract::virtual_* v) const { std::string result; - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .postcondition([&] (std::string const& result) { if(result != "") BOOST_CONTRACT_ASSERT(*result.rbegin() == '\n'); }) @@ -36,7 +36,7 @@ std::string lines::str(boost::contract::virtual_* v) const { std::string& lines::str(boost::contract::virtual_* v) { boost::optional result; - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .postcondition([&] (boost::optional const& result) { if(*result != "") BOOST_CONTRACT_ASSERT(*result->rbegin() == '\n'); }) @@ -46,7 +46,7 @@ std::string& lines::str(boost::contract::virtual_* v) { } void lines::put(std::string const& x, boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(*x.rbegin() != '\n'); }) @@ -55,7 +55,7 @@ void lines::put(std::string const& x, boost::contract::virtual_* v) { } void lines::put(char x, boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(x != '\n'); }) @@ -65,7 +65,7 @@ void lines::put(char x, boost::contract::virtual_* v) { void lines::put(int x, bool tab, boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(x >= 0); }) @@ -86,7 +86,7 @@ public: std::string str(boost::contract::virtual_* v = 0) const /* override */ { std::string result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_str // Note the use of `static_cast` (and same in other overloads below). >(v, result, static_cast(v, str_, static_cast(&string_lines::str), this); @@ -110,8 +110,8 @@ public: void put(std::string const& x, boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_str = - BOOST_CONTRACT_OLDOF(v, str()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, str()); + boost::contract::check c = boost::contract::public_function< override_put >(v, static_cast(&string_lines::put), this, x) @@ -126,8 +126,8 @@ public: // Overload on argument type. void put(char x, boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_str = - BOOST_CONTRACT_OLDOF(v, str()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, str()); + boost::contract::check c = boost::contract::public_function< override_put >(v, static_cast(&string_lines::put), this, x) @@ -143,8 +143,8 @@ public: void put(int x, bool tab = false, boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_str = - BOOST_CONTRACT_OLDOF(v, str()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, str()); + boost::contract::check c = boost::contract::public_function< override_put >(v, static_cast(&string_lines::put), this, x, tab) diff --git a/example/features/private_protected.cpp b/example/features/private_protected.cpp index d87a15d..7b79105 100644 --- a/example/features/private_protected.cpp +++ b/example/features/private_protected.cpp @@ -16,8 +16,8 @@ private: int n_; void dec() { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(get()); - boost::contract::guard c = boost::contract::function() + boost::contract::old_ptr old_get = BOOST_CONTRACT_OLD(get()); + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT( get() + 1 >= std::numeric_limits::min()); @@ -32,7 +32,7 @@ private: protected: virtual void set(int n, boost::contract::virtual_* = 0) { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(n <= 0); }) @@ -50,7 +50,7 @@ protected: public: virtual int get(boost::contract::virtual_* v = 0) const { int result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, this) .postcondition([&] (int const result) { BOOST_CONTRACT_ASSERT(result <= 0); diff --git a/example/features/private_protected_virtual.cpp b/example/features/private_protected_virtual.cpp index a3d23c8..ed2acbd 100644 --- a/example/features/private_protected_virtual.cpp +++ b/example/features/private_protected_virtual.cpp @@ -17,8 +17,8 @@ private: int n_; virtual void dec(boost::contract::virtual_* = 0) { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(get()); - boost::contract::guard c = boost::contract::function() + boost::contract::old_ptr old_get = BOOST_CONTRACT_OLD(get()); + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT( get() + 1 >= std::numeric_limits::min()); @@ -33,7 +33,7 @@ private: protected: virtual void set(int n, boost::contract::virtual_* = 0) { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(n <= 0); }) @@ -51,7 +51,7 @@ protected: public: virtual int get(boost::contract::virtual_* v = 0) const { int result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, this) .postcondition([&] (int const result) { BOOST_CONTRACT_ASSERT(result <= 0); @@ -83,8 +83,8 @@ public: // Not overriding from public members so no `override_...`. virtual void dec(boost::contract::virtual_* v = 0) { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(v, get()); - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::old_ptr old_get = BOOST_CONTRACT_OLD(v, get()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT( get() + 10 >= std::numeric_limits::min()); @@ -98,7 +98,7 @@ public: } virtual void set(int n, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(n % 10 == 0); }) @@ -115,7 +115,7 @@ public: virtual int get(boost::contract::virtual_* v = 0) const { int result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_get>(v, result, &counter10::get, this); return result = counter::get(); diff --git a/example/features/private_protected_virtual_multi.cpp b/example/features/private_protected_virtual_multi.cpp index bc85e2e..f633f8b 100644 --- a/example/features/private_protected_virtual_multi.cpp +++ b/example/features/private_protected_virtual_multi.cpp @@ -31,8 +31,8 @@ private: int n_; virtual void dec(boost::contract::virtual_* = 0) { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(get()); - boost::contract::guard c = boost::contract::function() + boost::contract::old_ptr old_get = BOOST_CONTRACT_OLD(get()); + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT( get() + 1 >= std::numeric_limits::min()); @@ -47,7 +47,7 @@ private: protected: virtual void set(int n, boost::contract::virtual_* = 0) { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(n <= 0); }) @@ -65,7 +65,7 @@ protected: public: virtual int get(boost::contract::virtual_* v = 0) const { int result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, this) .postcondition([&] (int const result) { BOOST_CONTRACT_ASSERT(result <= 0); @@ -101,8 +101,8 @@ public: //] void countable::dec(boost::contract::virtual_* v) { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(v, get()); - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::old_ptr old_get = BOOST_CONTRACT_OLD(v, get()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(get() > std::numeric_limits::min()); }) @@ -114,7 +114,7 @@ void countable::dec(boost::contract::virtual_* v) { } void countable::set(int n, boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(n <= 0); @@ -128,7 +128,7 @@ void countable::set(int n, boost::contract::virtual_* v) { int countable::get(boost::contract::virtual_* v) const { int result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, this); assert(false); // Never executed by this library. } @@ -145,8 +145,8 @@ public: // Overriding from public members from `countable` so use `override_...`. virtual void dec(boost::contract::virtual_* v = 0) { - boost::contract::old_ptr old_get = BOOST_CONTRACT_OLDOF(v, get()); - boost::contract::guard c = boost::contract::public_function< + boost::contract::old_ptr old_get = BOOST_CONTRACT_OLD(v, get()); + boost::contract::check c = boost::contract::public_function< override_dec>(v, &counter10::dec, this) .precondition([&] { BOOST_CONTRACT_ASSERT( @@ -161,7 +161,7 @@ public: } virtual void set(int n, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_set>(v, &counter10::set, this, n) .precondition([&] { BOOST_CONTRACT_ASSERT(n % 10 == 0); @@ -181,7 +181,7 @@ public: virtual int get(boost::contract::virtual_* v = 0) const { int result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_get>(v, result, &counter10::get, this); return result = counter::get(); diff --git a/example/features/public.cpp b/example/features/public.cpp index 8513d91..f95ded2 100644 --- a/example/features/public.cpp +++ b/example/features/public.cpp @@ -17,7 +17,7 @@ public: BOOST_CONTRACT_ASSERT(from <= to); }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == (to - from + 1)); }) @@ -33,7 +33,7 @@ public: //[public_destructor virtual ~unique_identifiers() { // Following contract checks invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); // Destructor body here... (do nothing in this example). } @@ -41,14 +41,14 @@ public: int size() const { // Following contract checks invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.size(); } //[public_function bool find(int id) const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { if(size() == 0) BOOST_CONTRACT_ASSERT(!result); }) @@ -65,10 +65,10 @@ public: virtual int push_back(int id, boost::contract::virtual_* v = 0) { int result; boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(id)); // Pass `v`. + BOOST_CONTRACT_OLD(v, find(id)); // Pass `v`. boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); // Pass `v`. - boost::contract::guard c = boost::contract::public_function( + BOOST_CONTRACT_OLD(v, size()); // Pass `v`. + boost::contract::check c = boost::contract::public_function( v, result, this) // Pass `v` and `result`. .precondition([&] { BOOST_CONTRACT_ASSERT(!find(id)); @@ -111,10 +111,9 @@ public: int push_back(int id, boost::contract::virtual_* v = 0) /* override */ { int result; boost::contract::old_ptr old_find = - BOOST_CONTRACT_OLDOF(v, find(id)); - boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, find(id)); + boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(v, size()); + boost::contract::check c = boost::contract::public_function< override_push_back // Pass override plus below function pointer... >(v, result, &identifiers::push_back, this, id) // ...and arguments. .precondition([&] { // Check in OR with bases. @@ -136,13 +135,13 @@ public: bool empty() const { // Following contract checks invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size() == 0; } identifiers(int from, int to) : unique_identifiers(from, to) { // Following contract checks invariants. - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } }; diff --git a/example/features/pure_virtual_public.cpp b/example/features/pure_virtual_public.cpp index 5903c8f..485d266 100644 --- a/example/features/pure_virtual_public.cpp +++ b/example/features/pure_virtual_public.cpp @@ -25,7 +25,7 @@ public: // Pure-virtual function definition (and contract) out-of-line (usual in C++). surface shape::get_surface(boost::contract::virtual_* v) const { boost::optional result; - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .postcondition([&] (boost::optional const& result) { BOOST_CONTRACT_ASSERT(result->area > 0); BOOST_CONTRACT_ASSERT(result->perimeter > 0); @@ -47,7 +47,7 @@ public: surface get_surface(boost::contract::virtual_* v = 0) const /* override */ { boost::optional result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_get_surface>(v, result, &square::get_surface, this) .postcondition([&] (boost::optional const& result) { BOOST_CONTRACT_ASSERT(result->area == edge() * edge()); @@ -69,17 +69,17 @@ public: edge_(edge) { // Check invariants. - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } ~square() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } int edge() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return edge_; } diff --git a/example/features/separate_body.hpp b/example/features/separate_body.hpp index a679005..5e21179 100644 --- a/example/features/separate_body.hpp +++ b/example/features/separate_body.hpp @@ -24,7 +24,7 @@ public: }), values_(new T[MaxSize]) // Still, member initializations must be here. { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == count); }) @@ -33,14 +33,14 @@ public: } virtual ~array() { - boost::contract::guard c = boost::contract::destructor(this); // Inv. + boost::contract::check c = boost::contract::destructor(this); // Inv. destructor_body(); // Separate destructor body implementation. } virtual void push_back(T const& value, boost::contract::virtual_* v = 0) { boost::contract::old_ptr old_size = - BOOST_CONTRACT_OLDOF(v, size()); - boost::contract::guard c = boost::contract::public_function(v, this) + BOOST_CONTRACT_OLD(v, size()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(size() < MaxSize); }) @@ -63,7 +63,7 @@ private: public: unsigned size() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size_body(); } diff --git a/example/features/static_public.cpp b/example/features/static_public.cpp index 28462a6..ceed184 100644 --- a/example/features/static_public.cpp +++ b/example/features/static_public.cpp @@ -17,7 +17,7 @@ public: static int instances() { // Explicit template parameter `make` (to check static invariants). - boost::contract::guard c = boost::contract::public_function(); + boost::contract::check c = boost::contract::public_function(); return instances_; // Function body. } @@ -27,8 +27,8 @@ public: make() : object() { boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::guard c = boost::contract::constructor(this) + BOOST_CONTRACT_OLD(instances()); + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1); }) @@ -39,8 +39,8 @@ public: ~make() { boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::guard c = boost::contract::destructor(this) + BOOST_CONTRACT_OLD(instances()); + boost::contract::check c = boost::contract::destructor(this) .postcondition([&] { // (An example of destructor postconditions.) BOOST_CONTRACT_ASSERT(instances() == *old_instances - 1); }) diff --git a/example/features/throw_on_failure.cpp b/example/features/throw_on_failure.cpp index c5c315a..0d751ce 100644 --- a/example/features/throw_on_failure.cpp +++ b/example/features/throw_on_failure.cpp @@ -32,7 +32,7 @@ public: /* ... */ //] - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == std::strlen(chars)); }) @@ -45,12 +45,12 @@ public: ~cstring() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } std::size_t size() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return size_; } @@ -66,15 +66,21 @@ private: }; //[throw_on_failure_handler -void throwing_handler(boost::contract::from context) { - if(context == boost::contract::from_destructor) { - // Ignore exception because destructors should never throw. - std::clog << "destructor contract failed (ignored)" << std::endl; - } else throw; // Re-throw (assertion_failure, too_large_error, etc.). -} - int main() { - boost::contract::set_failure(&throwing_handler); + boost::contract::set_specification_failure( + [] (boost::contract::from context) { + if(context == boost::contract::from_destructor) { + // Ignore exception because destructors should never throw. + std::clog << "destructor contract failed (ignored)" << + std::endl; + } else throw; // Rethrow (assertion_failure, too_large_error, etc.). + } + ); + boost::contract::set_check_failure( // Then do not use CHECK in destructors. + [] { + throw; // Rethrow (assertion_failure, too_large_error, etc.). + } + ); /* ... */ //] diff --git a/example/features/union.cpp b/example/features/union.cpp index 318c402..dacb47a 100644 --- a/example/features/union.cpp +++ b/example/features/union.cpp @@ -29,8 +29,8 @@ union positive { BOOST_CONTRACT_ASSERT(x > 0); }); boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::guard c = boost::contract::constructor(this) + BOOST_CONTRACT_OLD(instances()); + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1); }) @@ -46,8 +46,8 @@ union positive { BOOST_CONTRACT_ASSERT(x > 0); }); boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::guard c = boost::contract::constructor(this) + BOOST_CONTRACT_OLD(instances()); + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(instances() == *old_instances + 1); }) @@ -59,8 +59,8 @@ union positive { ~positive() { boost::contract::old_ptr old_instances = - BOOST_CONTRACT_OLDOF(instances()); - boost::contract::guard c = boost::contract::destructor(this) + BOOST_CONTRACT_OLD(instances()); + boost::contract::check c = boost::contract::destructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(instances() == *old_instances - 1); }) @@ -70,7 +70,7 @@ union positive { } void get(int& x) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(x > 0); }); @@ -80,7 +80,7 @@ union positive { } void get(double& x) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(x > 0); }); @@ -90,7 +90,7 @@ union positive { } static int instances() { - boost::contract::guard c = boost::contract::public_function(); + boost::contract::check c = boost::contract::public_function(); return instances_; } diff --git a/example/features/volatile.cpp b/example/features/volatile.cpp index 6b222ef..d0cf598 100644 --- a/example/features/volatile.cpp +++ b/example/features/volatile.cpp @@ -14,27 +14,27 @@ public: void invariant() const; // Invariants const qualified. a() { // Check both cv and const invariant (at exit if no throw). - boost::contract::guard c= boost::contract::constructor(this); + boost::contract::check c= boost::contract::constructor(this); } ~a() { // Check both cv and const invariant (at entry). - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } void m() { // Check const invariant (at entry and exit if no throw). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } void c() const { // Check const invariant (at entry and exit if no throw). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } void v() volatile { // Check cv invariant (at entry and exit if no throw). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } void cv() const volatile { // Check cv inv. (at entry and exit if no throw). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } }; //] diff --git a/example/meyer97/stack3.cpp b/example/meyer97/stack3.cpp index c608a90..56dc112 100644 --- a/example/meyer97/stack3.cpp +++ b/example/meyer97/stack3.cpp @@ -38,7 +38,7 @@ public: // Create stack for max of n items, if n < 0 set error (no preconditions). explicit stack3(int n, T const& default_value = T()) : stack_(0), error_(no_error) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { // Error if impossible. BOOST_CONTRACT_ASSERT((n < 0) == (error() == size_error)); @@ -58,20 +58,20 @@ public: // Max number of stack items. int capacity() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return stack_.capacity(); } // Number of stack items. int count() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return stack_.count(); } // Top item if present, otherwise none and set error (no preconditions). boost::optional item() const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Error if impossible. BOOST_CONTRACT_ASSERT(empty() == (error() == underflow_error)); @@ -94,19 +94,19 @@ public: // Error indicator set by various operations. error_code error() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return error_; } bool empty() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return stack_.empty(); } bool full() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return stack_.full(); } @@ -114,9 +114,9 @@ public: // Add x to top if capacity allows, otherwise set error (no preconditions). void put(T const& x) { - boost::contract::old_ptr old_full = BOOST_CONTRACT_OLDOF(full()); - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_full = BOOST_CONTRACT_OLD(full()); + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Error if impossible. BOOST_CONTRACT_ASSERT(*old_full == (error() == overflow_error)); @@ -140,10 +140,9 @@ public: // Remove top item if possible, otherwise set error (no preconditions). void remove() { - boost::contract::old_ptr old_empty = - BOOST_CONTRACT_OLDOF(empty()); - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_empty = BOOST_CONTRACT_OLD(empty()); + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Error if impossible. BOOST_CONTRACT_ASSERT(*old_empty == (error() == diff --git a/example/meyer97/stack4.hpp b/example/meyer97/stack4.hpp index 4234d19..947e70f 100644 --- a/example/meyer97/stack4.hpp +++ b/example/meyer97/stack4.hpp @@ -36,7 +36,7 @@ public: BOOST_CONTRACT_ASSERT(n >= 0); // Non-negative capacity. }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(capacity() == n); // Capacity set. }) @@ -49,7 +49,7 @@ public: // Deep copy via constructor. /* implicit */ stack4(stack4 const& other) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(capacity() == other.capacity()); BOOST_CONTRACT_ASSERT(count() == other.count()); @@ -65,7 +65,7 @@ public: // Deep copy via assignment. stack4& operator=(stack4 const& other) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(capacity() == other.capacity()); BOOST_CONTRACT_ASSERT(count() == other.count()); @@ -84,7 +84,7 @@ public: // Destroy this stack. virtual ~stack4() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); delete[] array_; } @@ -93,20 +93,20 @@ public: // Max number of stack items. int capacity() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return capacity_; } // Number of stack items. int count() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return count_; } // Top item. T const& item() const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); // Not empty (count > 0). }) @@ -120,7 +120,7 @@ public: // Is stack empty? bool empty() const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Empty definition. BOOST_CONTRACT_ASSERT(result == (count() == 0)); @@ -133,7 +133,7 @@ public: // Is stack full? bool full() const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT( // Full definition. result == (count() == capacity())); @@ -147,8 +147,8 @@ public: // Add x on top. void put(T const& x) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!full()); // Not full. }) @@ -164,8 +164,8 @@ public: // Remove top item. void remove() { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); // Not empty (count > 0). }) diff --git a/example/mitchell02/counter/counter.hpp b/example/mitchell02/counter/counter.hpp index 91826b6..0cae53d 100644 --- a/example/mitchell02/counter/counter.hpp +++ b/example/mitchell02/counter/counter.hpp @@ -24,7 +24,7 @@ public: // Construct counter with specified value. explicit counter(int a_value = 10) : value_(a_value) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(value() == a_value); // Value set. }) @@ -33,14 +33,14 @@ public: // Destroy counter. virtual ~counter() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Queries */ // Current counter value. int value() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return value_; } @@ -48,8 +48,8 @@ public: // Decrement counter value. void decrement() { - boost::contract::old_ptr old_value = BOOST_CONTRACT_OLDOF(value()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_value = BOOST_CONTRACT_OLD(value()); + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(value() == *old_value - 1); // Decrement. }) diff --git a/example/mitchell02/counter/decrement_button.hpp b/example/mitchell02/counter/decrement_button.hpp index b82887e..0eea5e5 100644 --- a/example/mitchell02/counter/decrement_button.hpp +++ b/example/mitchell02/counter/decrement_button.hpp @@ -28,7 +28,7 @@ public: /* Creation */ explicit decrement_button(counter& a_counter) : counter_(a_counter) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { // Enable iff positive value. BOOST_CONTRACT_ASSERT(enabled() == (a_counter.value() > 0)); @@ -39,7 +39,7 @@ public: // Destroy button. virtual ~decrement_button() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Commands */ @@ -47,8 +47,8 @@ public: virtual void on_bn_clicked(boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_value = - BOOST_CONTRACT_OLDOF(v, counter_.value()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, counter_.value()); + boost::contract::check c = boost::contract::public_function< override_on_bn_clicked >(v, &decrement_button::on_bn_clicked, this) .postcondition([&] { @@ -62,7 +62,7 @@ public: virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0) const /* override */ { bool result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_up_to_date_with_subject >(v, result, &decrement_button::up_to_date_with_subject, this); @@ -70,7 +70,7 @@ public: } virtual void update(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_update>(v, &decrement_button::update, this) .postcondition([&] { // Enabled iff positive value. diff --git a/example/mitchell02/counter/push_button.hpp b/example/mitchell02/counter/push_button.hpp index ea580f4..ba66286 100644 --- a/example/mitchell02/counter/push_button.hpp +++ b/example/mitchell02/counter/push_button.hpp @@ -19,7 +19,7 @@ public: // Create an enabled button. push_button() : enabled_(true) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(enabled()); // Enabled. }) @@ -28,14 +28,14 @@ public: // Destroy button. virtual ~push_button() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Queries */ // If button is enabled. bool enabled() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return enabled_; } @@ -43,7 +43,7 @@ public: // Enable button. void enable() { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(enabled()); // Enabled. }) @@ -54,7 +54,7 @@ public: // Disable button. void disable() { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(!enabled()); // Disabled. }) @@ -71,7 +71,7 @@ private: }; void push_button::on_bn_clicked(boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(enabled()); // Enabled. }) diff --git a/example/mitchell02/counter_main.cpp b/example/mitchell02/counter_main.cpp index a621076..1200752 100644 --- a/example/mitchell02/counter_main.cpp +++ b/example/mitchell02/counter_main.cpp @@ -26,7 +26,7 @@ public: // Create view associated with given counter. explicit view_of_counter(counter& a_counter) : counter_(a_counter) { - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); counter_.attach(this); assert(counter_.value() == test_counter); @@ -34,7 +34,7 @@ public: // Destroy view. virtual ~view_of_counter() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Commands */ @@ -42,7 +42,7 @@ public: virtual bool up_to_date_with_subject(boost::contract::virtual_* v = 0) const /* override */ { bool result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_up_to_date_with_subject >(v, result, &view_of_counter::up_to_date_with_subject, this); @@ -50,7 +50,7 @@ public: } virtual void update(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_update>(v, &view_of_counter::update, this); assert(counter_.value() == test_counter); diff --git a/example/mitchell02/courier.cpp b/example/mitchell02/courier.cpp index e435cf8..5866264 100644 --- a/example/mitchell02/courier.cpp +++ b/example/mitchell02/courier.cpp @@ -61,13 +61,13 @@ public: insurance_cover_usd_(_insurance_cover_usd) { // Check invariants. - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } // Destroy courier. virtual ~courier() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Queries */ @@ -75,7 +75,7 @@ public: // Return insurance cover. double insurance_cover_usd() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return insurance_cover_usd_; } @@ -87,7 +87,7 @@ public: std::string const& destination, boost::contract::virtual_* v = 0 ) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { // Within max weight of this delivery. BOOST_CONTRACT_ASSERT(package_delivery.weight_kg < 5.0); @@ -148,13 +148,13 @@ public: courier(insurance_cover_usd) { // Check invariants. - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } // Destroy courier. virtual ~different_courier() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Commands */ @@ -164,7 +164,7 @@ public: std::string const& destination, boost::contract::virtual_* v = 0 ) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_deliver >(v, &different_courier::deliver, this, package_delivery, destination) .precondition([&] { diff --git a/example/mitchell02/customer_manager.cpp b/example/mitchell02/customer_manager.cpp index b4610f8..c3cf5e5 100644 --- a/example/mitchell02/customer_manager.cpp +++ b/example/mitchell02/customer_manager.cpp @@ -41,32 +41,32 @@ public: customer_manager() { // Check invariants. - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } virtual ~customer_manager() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Basic Queries */ int count() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return customers_.size(); } bool id_active(customer_info::identifier const& id) const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return customers_.find(id) != customers_.cend(); } /* Derived Queries */ std::string const& name_for(customer_info::identifier const& id) const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(id_active(id)); // Active. }) @@ -79,8 +79,8 @@ public: /* Commands */ void add(customer_info const& info) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { // Not already active. BOOST_CONTRACT_ASSERT(!id_active(info.id)); @@ -96,7 +96,7 @@ public: void set_name(customer_info::identifier const& id, std::string const& name) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(id_active(id)); // Already active. }) diff --git a/example/mitchell02/dictionary.cpp b/example/mitchell02/dictionary.cpp index 5f16712..98ce9fc 100644 --- a/example/mitchell02/dictionary.cpp +++ b/example/mitchell02/dictionary.cpp @@ -23,7 +23,7 @@ public: // Create empty dictionary. dictionary() { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(count() == 0); // Empty. }) @@ -33,7 +33,7 @@ public: // Destroy dictionary. ~dictionary() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Basic Queries */ @@ -41,14 +41,14 @@ public: // Number of key entries. int count() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return items_.size(); } // Has entry for key? bool has(K const& key) const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Empty has no key. if(count() == 0) BOOST_CONTRACT_ASSERT(!result); @@ -60,7 +60,7 @@ public: // Value for a given key. T const& value_for(K const& key) const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(has(key)); // Has key. }) @@ -74,8 +74,8 @@ public: // Add value of a given key. void put(K const& key, T const& value) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!has(key)); // Has not key already. }) @@ -92,8 +92,8 @@ public: // Remove value for given key. void remove(K const& key) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(has(key)); // Has key. }) diff --git a/example/mitchell02/name_list.cpp b/example/mitchell02/name_list.cpp index cb38603..b67ebde 100644 --- a/example/mitchell02/name_list.cpp +++ b/example/mitchell02/name_list.cpp @@ -24,7 +24,7 @@ public: // Create an empty list. name_list() { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(count() == 0); // Empty list. }) @@ -34,7 +34,7 @@ public: // Destroy list. virtual ~name_list() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Basic Queries */ @@ -42,14 +42,14 @@ public: // Number of names in list. int count() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return names_.size(); } // Is name in list? bool has(std::string const& name) const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // If empty, has not. if(count() == 0) BOOST_CONTRACT_ASSERT(!result); @@ -66,10 +66,10 @@ public: virtual void put(std::string const& name, boost::contract::virtual_* v = 0) { boost::contract::old_ptr old_has_name = - BOOST_CONTRACT_OLDOF(v, has(name)); + BOOST_CONTRACT_OLD(v, has(name)); boost::contract::old_ptr old_count = - BOOST_CONTRACT_OLDOF(v, count()); - boost::contract::guard c = boost::contract::public_function(v, this) + BOOST_CONTRACT_OLD(v, count()); + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { BOOST_CONTRACT_ASSERT(!has(name)); // Not already in list. }) @@ -104,10 +104,10 @@ public: void put(std::string const& name, boost::contract::virtual_* v = 0) /* override */ { boost::contract::old_ptr old_has_name = - BOOST_CONTRACT_OLDOF(v, has(name)); + BOOST_CONTRACT_OLD(v, has(name)); boost::contract::old_ptr old_count = - BOOST_CONTRACT_OLDOF(v, count()); - boost::contract::guard c = boost::contract::public_function< + BOOST_CONTRACT_OLD(v, count()); + boost::contract::check c = boost::contract::public_function< override_put>(v, &relaxed_name_list::put, this, name) .precondition([&] { // Relax inherited preconditions. BOOST_CONTRACT_ASSERT(has(name)); // Already in list. diff --git a/example/mitchell02/observer/observer.hpp b/example/mitchell02/observer/observer.hpp index b01d7ef..591291e 100644 --- a/example/mitchell02/observer/observer.hpp +++ b/example/mitchell02/observer/observer.hpp @@ -20,11 +20,11 @@ public: /* Creation */ observer() { - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } virtual ~observer() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Commands */ @@ -38,13 +38,13 @@ public: }; bool observer::up_to_date_with_subject(boost::contract::virtual_* v) const { - boost::contract::guard c = boost::contract::public_function(v, this); + boost::contract::check c = boost::contract::public_function(v, this); assert(false); return false; } void observer::update(boost::contract::virtual_* v) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .postcondition([&] { BOOST_CONTRACT_ASSERT(up_to_date_with_subject()); // Up-to-date. }) diff --git a/example/mitchell02/observer/subject.hpp b/example/mitchell02/observer/subject.hpp index b74499d..d68a791 100644 --- a/example/mitchell02/observer/subject.hpp +++ b/example/mitchell02/observer/subject.hpp @@ -35,20 +35,20 @@ public: // Construct subject with no observer. subject() { // Check invariant. - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } // Destroy subject. virtual ~subject() { // Check invariant. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Queries */ // If given object is attached. bool attached(observer const* ob) const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(ob); // Not null. }) @@ -63,8 +63,8 @@ public: // Attach given object as an observer. void attach(observer* ob) { boost::contract::old_ptr > old_observers = - BOOST_CONTRACT_OLDOF(observers()); - boost::contract::guard c = boost::contract::public_function(this) + BOOST_CONTRACT_OLD(observers()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(ob); // Not null. BOOST_CONTRACT_ASSERT(!attached(ob)); // Not already attached. @@ -102,7 +102,7 @@ protected: // Update all attached observers. void notify() { // Protected members use `function` (no inv and no subcontracting). - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .postcondition([&] { if(O_N <= COMPLEXITY_MAX) { // All updated. @@ -137,7 +137,7 @@ private: observer const* ob ) { // Private members use `function` (no inv and no subcontracting). - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(ob); // Not null. }) diff --git a/example/mitchell02/observer_main.cpp b/example/mitchell02/observer_main.cpp index 0f5c21e..054b26b 100644 --- a/example/mitchell02/observer_main.cpp +++ b/example/mitchell02/observer_main.cpp @@ -25,15 +25,15 @@ public: typedef int state; // Some state being observed. concrete_subject() : state_() { - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } ~concrete_subject() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } void set_state(state const& new_state) { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); state_ = new_state; assert(state_ == test_state); @@ -41,7 +41,7 @@ public: } state get_state() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return state_; } @@ -63,11 +63,11 @@ public: // Create concrete observer. explicit concrete_observer(concrete_subject const& subj) : subject_(subj), observed_state_() { - boost::contract::guard c = boost::contract::constructor(this); + boost::contract::check c = boost::contract::constructor(this); } ~concrete_observer() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } // Implement base virtual functions. @@ -75,7 +75,7 @@ public: bool up_to_date_with_subject(boost::contract::virtual_* v = 0) const /* override */ { bool result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_up_to_date_with_subject >(v, result, &concrete_observer::up_to_date_with_subject, this); @@ -83,7 +83,7 @@ public: } void update(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_update>(v, &concrete_observer::update, this); observed_state_ = subject_.get_state(); diff --git a/example/mitchell02/simple_queue.cpp b/example/mitchell02/simple_queue.cpp index 203112d..082cd51 100644 --- a/example/mitchell02/simple_queue.cpp +++ b/example/mitchell02/simple_queue.cpp @@ -39,7 +39,7 @@ public: BOOST_CONTRACT_ASSERT(a_capacity > 0); // Positive capacity. }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { // Capacity set. BOOST_CONTRACT_ASSERT(capacity() == a_capacity); @@ -53,7 +53,7 @@ public: // Destroy queue. virtual ~simple_queue() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Basic Queries */ @@ -62,14 +62,14 @@ public: // (Somewhat exposes implementation but allows to check more contracts.) std::vector const& items() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return items_; } // Max number of items queue can hold. int capacity() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return items_.capacity(); } @@ -78,7 +78,7 @@ public: // Number of items. int count() const { int result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Return items count. BOOST_CONTRACT_ASSERT(result == int(items().size())); @@ -91,7 +91,7 @@ public: // Item at head. T const& head() const { boost::optional result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!is_empty()); // Not empty. }) @@ -107,7 +107,7 @@ public: // If queue contains no item. bool is_empty() const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Consistent with count. BOOST_CONTRACT_ASSERT(result == (count() == 0)); @@ -120,7 +120,7 @@ public: // If queue as no room for another item. bool is_full() const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT( // Consistent with size and capacity. result == (capacity() == int(items().size()))); @@ -136,9 +136,9 @@ public: void remove() { // Expensive all_equal postcond. and old_items copy might be skipped. boost::contract::old_ptr > old_items; - if(O_N <= COMPLEXITY_MAX) old_items = BOOST_CONTRACT_OLDOF(items()); - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + if(O_N <= COMPLEXITY_MAX) old_items = BOOST_CONTRACT_OLD(items()); + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!is_empty()); // Not empty. }) @@ -155,9 +155,9 @@ public: void put(T const& item) { // Expensive all_equal postcond. and old_items copy might be skipped. boost::contract::old_ptr > old_items; - if(O_N <= COMPLEXITY_MAX) old_items = BOOST_CONTRACT_OLDOF(items()); - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + if(O_N <= COMPLEXITY_MAX) old_items = BOOST_CONTRACT_OLD(items()); + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(count() < capacity()); // Room for add. }) @@ -176,7 +176,7 @@ private: // Contract helper. static bool all_equal(std::vector const& left, std::vector const& right, unsigned offset = 0) { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { // Correct offset. BOOST_CONTRACT_ASSERT(right.size() == left.size() + offset); diff --git a/example/mitchell02/stack.cpp b/example/mitchell02/stack.cpp index f3faad1..2eed3e2 100644 --- a/example/mitchell02/stack.cpp +++ b/example/mitchell02/stack.cpp @@ -23,7 +23,7 @@ public: // Create empty stack. stack() { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(count() == 0); // Empty. }) @@ -33,7 +33,7 @@ public: // Destroy stack. virtual ~stack() { // Check invariants. - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } /* Basic Queries */ @@ -41,13 +41,13 @@ public: // Number of items. int count() const { // Check invariants. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return items_.size(); } // Item at index in [1, count()] (as in Eiffel). T const& item_at(int index) const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(index > 0); // Positive index. BOOST_CONTRACT_ASSERT(index <= count()); // Index within count. @@ -62,7 +62,7 @@ public: // If no items. bool is_empty() const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { // Consistent with count. BOOST_CONTRACT_ASSERT(result == (count() == 0)); @@ -75,7 +75,7 @@ public: // Top item. T const& item() const { boost::optional result; // Avoid extra construction of T. - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(count() > 0); // Not empty. }) @@ -92,8 +92,8 @@ public: // Push item to the top. void put(T const& new_item) { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(count() == *old_count + 1); // Count inc. BOOST_CONTRACT_ASSERT(item() == new_item); // Item set. @@ -105,8 +105,8 @@ public: // Pop top item. void remove() { - boost::contract::old_ptr old_count = BOOST_CONTRACT_OLDOF(count()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::old_ptr old_count = BOOST_CONTRACT_OLD(count()); + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(count() > 0); // Not empty. }) diff --git a/example/n1962/circle.cpp b/example/n1962/circle.cpp index 8ff8434..2bd4633 100644 --- a/example/n1962/circle.cpp +++ b/example/n1962/circle.cpp @@ -17,7 +17,7 @@ public: unsigned shape::compute_area(boost::contract::virtual_* v) const { unsigned result; - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .postcondition([&] (int const& result) { BOOST_CONTRACT_ASSERT(result > 0); }) @@ -39,7 +39,7 @@ public: static int const pi = 3; // Truncated to int from 3.14... explicit circle(unsigned a_radius) : radius_(a_radius) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(radius() == a_radius); }) @@ -49,7 +49,7 @@ public: virtual unsigned compute_area(boost::contract::virtual_* v = 0) const /* override */ { unsigned result; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_compute_area>(v, result, &circle::compute_area, this) .postcondition([&] (unsigned const& result) { BOOST_CONTRACT_ASSERT(result == pi * radius() * radius()); @@ -60,7 +60,7 @@ public: } unsigned radius() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return radius_; } diff --git a/example/n1962/equal.cpp b/example/n1962/equal.cpp index 80a9493..6c1515e 100644 --- a/example/n1962/equal.cpp +++ b/example/n1962/equal.cpp @@ -15,7 +15,7 @@ bool operator==(T const& left, T const& right); template bool operator!=(T const& left, T const& right) { bool result; - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .postcondition([&] { BOOST_CONTRACT_ASSERT(result == !(left == right)); }) @@ -27,7 +27,7 @@ bool operator!=(T const& left, T const& right) { template bool operator==(T const& left, T const& right) { bool result; - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .postcondition([&] { BOOST_CONTRACT_ASSERT(result == !(left != right)); }) diff --git a/example/n1962/factorial.cpp b/example/n1962/factorial.cpp index fc8995d..17a1d83 100644 --- a/example/n1962/factorial.cpp +++ b/example/n1962/factorial.cpp @@ -16,7 +16,7 @@ int factorial(int n ) { int result; - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(n >= 0); // Non-negative natural number. BOOST_CONTRACT_ASSERT(n <= 12); // Max function input. diff --git a/example/n1962/sqrt.cpp b/example/n1962/sqrt.cpp index fad1c44..a379f3b 100644 --- a/example/n1962/sqrt.cpp +++ b/example/n1962/sqrt.cpp @@ -11,7 +11,7 @@ double mysqrt(double x, double precision = 1e-6) { double result; - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(x >= 0.0); }) diff --git a/example/n1962/sum.cpp b/example/n1962/sum.cpp index 921c350..f5dd654 100644 --- a/example/n1962/sum.cpp +++ b/example/n1962/sum.cpp @@ -10,7 +10,7 @@ int sum(int count, int* array) { int result; - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { BOOST_CONTRACT_ASSERT(count % 4 == 0); }) diff --git a/example/n1962/vector.cpp b/example/n1962/vector.cpp index 363eb92..b28dbec 100644 --- a/example/n1962/vector.cpp +++ b/example/n1962/vector.cpp @@ -56,7 +56,7 @@ public: const_reverse_iterator; vector() : vect_() { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(empty()); }) @@ -64,7 +64,7 @@ public: } explicit vector(Allocator const& alloc) : vect_(alloc) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(empty()); BOOST_CONTRACT_ASSERT(get_allocator() == alloc); @@ -73,7 +73,7 @@ public: } explicit vector(size_type count) : vect_(count) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == count); BOOST_CONTRACT_ASSERT( @@ -86,7 +86,7 @@ public: } vector(size_type count, T const& value) : vect_(count, value) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == count); BOOST_CONTRACT_ASSERT( @@ -101,7 +101,7 @@ public: vector(size_type count, const T& value, Allocator const& alloc) : vect_(count, value, alloc) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == count); BOOST_CONTRACT_ASSERT( @@ -117,7 +117,7 @@ public: template vector(InputIter first, InputIter last) : vect_(first, last) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(std::distance(first, last) == int(size())); @@ -128,7 +128,7 @@ public: template vector(InputIter first, InputIter last, Allocator const& alloc) : vect_(first, last, alloc) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(std::distance(first, last) == int(size())); @@ -138,7 +138,7 @@ public: } /* implicit */ vector(vector const& other) : vect_(other.vect_) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .postcondition([&] { BOOST_CONTRACT_ASSERT( boost::contract::condition_if >( @@ -152,7 +152,7 @@ public: vector& operator=(vector const& other) { boost::optional result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT( boost::contract::condition_if >( @@ -174,11 +174,11 @@ public: } virtual ~vector() { - boost::contract::guard c = boost::contract::destructor(this); + boost::contract::check c = boost::contract::destructor(this); } void reserve(size_type count) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(count < max_size()); }) @@ -192,7 +192,7 @@ public: size_type capacity() const { size_type result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(result >= size()); }) @@ -203,7 +203,7 @@ public: iterator begin() { iterator result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { if(empty()) BOOST_CONTRACT_ASSERT(result == end()); }) @@ -214,7 +214,7 @@ public: const_iterator begin() const { const_iterator result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { if(empty()) BOOST_CONTRACT_ASSERT(result == end()); }) @@ -224,18 +224,18 @@ public: } iterator end() { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.end(); } const_iterator end() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.end(); } reverse_iterator rbegin() { iterator result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { if(empty()) BOOST_CONTRACT_ASSERT(result == rend()); }) @@ -246,7 +246,7 @@ public: const_reverse_iterator rbegin() const { const_reverse_iterator result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { if(empty()) BOOST_CONTRACT_ASSERT(result == rend()); }) @@ -256,19 +256,19 @@ public: } reverse_iterator rend() { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.rend(); } const_reverse_iterator rend() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.rend(); } void resize(size_type count, T const& value = T()) { boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(size()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(size() == count); if(count > *old_size) { @@ -287,7 +287,7 @@ public: size_type size() const { size_type result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(result <= capacity()); }) @@ -298,7 +298,7 @@ public: size_type max_size() const { size_type result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(result >= capacity()); }) @@ -309,7 +309,7 @@ public: bool empty() const { bool result; - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(result == (size() == 0)); }) @@ -319,24 +319,24 @@ public: } Allocator get_allocator() const { - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.get_allocator(); } reference at(size_type index) { // No precondition because throws out_of_range for invalid index. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.at(index); } const_reference at(size_type index) const { // No precondition because throws out_of_range for invalid index. - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); return vect_.at(index); } reference operator[](size_type index) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(index < size()); }) @@ -346,7 +346,7 @@ public: } const_reference operator[](size_type index) const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(index < size()); }) @@ -356,7 +356,7 @@ public: } reference front() { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) @@ -366,7 +366,7 @@ public: } const_reference front() const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) @@ -376,7 +376,7 @@ public: } reference back() { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) @@ -386,7 +386,7 @@ public: } const_reference back() const { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) @@ -400,7 +400,7 @@ public: BOOST_CONTRACT_OLD(size()); boost::contract::old_ptr old_capacity = BOOST_CONTRACT_OLD(capacity()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(size() < max_size()); }) @@ -422,7 +422,7 @@ public: void pop_back() { boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(size()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); }) @@ -436,7 +436,7 @@ public: template void assign(InputIter first, InputIter last) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) // Precondition: [begin(), end()) does not contain [first, last). .postcondition([&] { BOOST_CONTRACT_ASSERT(std::distance(first, last) == @@ -448,7 +448,7 @@ public: } void assign(size_type count, T const& value) { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(count <= max_size()); }) @@ -469,7 +469,7 @@ public: iterator result; boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(size()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(size() < max_size()); }) @@ -498,7 +498,7 @@ public: BOOST_CONTRACT_OLD(capacity()); boost::contract::old_ptr old_where = BOOST_CONTRACT_OLD(where); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(size() + count < max_size()); }) @@ -530,7 +530,7 @@ public: BOOST_CONTRACT_OLD(size()); boost::contract::old_ptr old_capacity = BOOST_CONTRACT_OLD(capacity()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(size() + std::distance(first, last) < max_size()); @@ -550,7 +550,7 @@ public: iterator result; boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(size()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(!empty()); BOOST_CONTRACT_ASSERT(where != end()); @@ -569,7 +569,7 @@ public: iterator result; boost::contract::old_ptr old_size = BOOST_CONTRACT_OLD(size()); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { BOOST_CONTRACT_ASSERT(size() >= std::distance(first, last)); }) @@ -585,7 +585,7 @@ public: } void clear() { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT(empty()); }) @@ -597,7 +597,7 @@ public: void swap(vector& other) { boost::contract::old_ptr old_me = BOOST_CONTRACT_OLD(*this); boost::contract::old_ptr old_other = BOOST_CONTRACT_OLD(other); - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .postcondition([&] { BOOST_CONTRACT_ASSERT( boost::contract::condition_if (or has_old) instead of boost::is_copy_constructible 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 (or has_old) instead of boost::is_copy_constructible 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 #include diff --git a/include/boost/contract/assert.hpp b/include/boost/contract/assert.hpp index dfc3dab..0c245b2 100644 --- a/include/boost/contract/assert.hpp +++ b/include/boost/contract/assert.hpp @@ -20,7 +20,7 @@ Facility to assert contract conditions. !defined(BOOST_CONTRACT_NO_INVARIANTS) #include #define BOOST_CONTRACT_ASSERT(condition) \ - { BOOST_CONTRACT_DETAIL_ASSERT(condition); } + BOOST_CONTRACT_DETAIL_ASSERT(condition) /* no `;` here */ #else /** Preferred way to assert contract conditions. diff --git a/include/boost/contract/check.hpp b/include/boost/contract/check.hpp index d983155..0a4d263 100644 --- a/include/boost/contract/check.hpp +++ b/include/boost/contract/check.hpp @@ -12,9 +12,9 @@ RAII object to check contracts. */ #include -#include +#include #include -#include +#include #include #include #include @@ -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).check_.release()) \ + : cond_(const_cast(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(other).check_.release()) + !defined(BOOST_CONTRACT_NO_EXCEPTS) + : cond_(const_cast(other).cond_.release()) #endif {} @@ -112,11 +115,11 @@ public: otherwise this is always @c void. */ template - /* implicit */ check(specify_precondition_old_postcondition - const& contract) + /* implicit */ check(specify_precondition_old_postcondition_except< + VirtualResult> const& contract) #ifndef DOXYGEN BOOST_CONTRACT_CHECK_CTOR_DEF_( - specify_precondition_old_postcondition) + specify_precondition_old_postcondition_except) #else ; #endif @@ -138,10 +141,11 @@ public: otherwise this is always @c void. */ template - /* implicit */ check(specify_old_postcondition const& + /* implicit */ check(specify_old_postcondition_except const& contract) #ifndef DOXYGEN - BOOST_CONTRACT_CHECK_CTOR_DEF_(specify_old_postcondition) + BOOST_CONTRACT_CHECK_CTOR_DEF_( + specify_old_postcondition_except) #else ; #endif @@ -163,11 +167,18 @@ public: otherwise this is always @c void. */ template - /* implicit */ check(specify_postcondition_only const& + /* implicit */ check(specify_postcondition_except const& contract) #ifndef DOXYGEN BOOST_CONTRACT_CHECK_CTOR_DEF_( - specify_postcondition_only) + specify_postcondition_except) + #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 - check_; + !defined(BOOST_CONTRACT_NO_EXCEPTS) + boost::contract::detail::auto_ptr + cond_; #endif /** @endcond */ }; diff --git a/include/boost/contract/constructor.hpp b/include/boost/contract/constructor.hpp index b315d58..9d8e44a 100644 --- a/include/boost/contract/constructor.hpp +++ b/include/boost/contract/constructor.hpp @@ -12,12 +12,12 @@ Program contracts for constructors. */ #include -#if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \ +#if !defined(BOOST_CONTRACT_NO_CONSTRUCTORS) || \ !defined(BOOST_CONTRACT_NO_PRECONDITIONS) #include #endif -#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) - #include +#ifndef BOOST_CONTRACT_NO_PRECONDITIONS + #include #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 -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(obj)); #else - return specify_old_postcondition<>(); + return specify_old_postcondition_except<>(); #endif } @@ -88,10 +88,10 @@ public: template 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); } diff --git a/include/boost/contract/core/access.hpp b/include/boost/contract/core/access.hpp index 74b553a..e36f796 100644 --- a/include/boost/contract/core/access.hpp +++ b/include/boost/contract/core/access.hpp @@ -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 - 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 - 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) diff --git a/include/boost/contract/core/config.hpp b/include/boost/contract/core/config.hpp index 0ac0f87..eaac0eb 100644 --- a/include/boost/contract/core/config.hpp +++ b/include/boost/contract/core/config.hpp @@ -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) diff --git a/include/boost/contract/core/exception.hpp b/include/boost/contract/core/exception.hpp index d013a43..b11f0c8 100644 --- a/include/boost/contract/core/exception.hpp +++ b/include/boost/contract/core/exception.hpp @@ -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 diff --git a/include/boost/contract/core/specify.hpp b/include/boost/contract/core/specify.hpp index 88f48da..5afd263 100644 --- a/include/boost/contract/core/specify.hpp +++ b/include/boost/contract/core/specify.hpp @@ -13,32 +13,102 @@ Facilities to specify preconditions, old value assignments, and postconditions. #include #include -#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 - #include + !defined(BOOST_CONTRACT_NO_EXCEPTS) + #include + #include #include #include #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 #endif #include +// 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_; + + #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( \ + BOOST_CONTRACT_SPECIFY_COND_RELEASE_); +#else + #define BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_ \ + return specify_old_postcondition_except( \ + 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( \ + BOOST_CONTRACT_SPECIFY_COND_RELEASE_); +#else + #define BOOST_CONTRACT_SPECIFY_OLD_IMPL_ \ + return specify_postcondition_except( \ + 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 - class specify_precondition_old_postcondition; template - class specify_old_postcondition; + class specify_precondition_old_postcondition_except; template - class specify_postcondition_only; + class specify_old_postcondition_except; + + template + 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_; - #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 - friend class specify_precondition_old_postcondition; + friend class specify_precondition_old_postcondition_except; template - friend class specify_old_postcondition; + friend class specify_old_postcondition_except; template - 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 + 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 + friend class specify_precondition_old_postcondition_except; + + template + friend class specify_old_postcondition_except; + + template + 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 -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 - 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 + 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::type> check_type; - - explicit specify_postcondition_only(check_type* check) : - check_(check) {} - - boost::contract::detail::auto_ptr check_; - #endif + BOOST_CONTRACT_SPECIFY_COND_CTOR_( + specify_postcondition_except, + boost::contract::detail::cond_with_post::type> + ) // Friends (used to limit library's public API). friend class check; - friend class specify_precondition_old_postcondition; - friend class specify_old_postcondition; + friend class specify_precondition_old_postcondition_except; + friend class specify_old_postcondition_except; /** @endcond */ }; @@ -175,7 +257,7 @@ body execution and to check postconditions. this is always @c void. */ template -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 - specify_postcondition_only 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(check_.release()); - #else - return specify_postcondition_only(); - #endif + specify_postcondition_except old(F const& f) { + BOOST_CONTRACT_SPECIFY_OLD_IMPL_ } /** @@ -244,44 +316,33 @@ public: not allow to specify any additional contract. */ template - 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 + 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::type> check_type; - - explicit specify_old_postcondition(check_type* check) : - check_(check) {} - - boost::contract::detail::auto_ptr check_; - #endif + BOOST_CONTRACT_SPECIFY_COND_CTOR_( + specify_old_postcondition_except, + boost::contract::detail::cond_with_post::type> + ) // Friends (used to limit library's public API). friend class check; - friend class specify_precondition_old_postcondition; + friend class specify_precondition_old_postcondition_except; template - friend specify_old_postcondition<> constructor(C*); + friend specify_old_postcondition_except<> constructor(C*); template - 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 - specify_old_postcondition 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(check_.release()); - #else - return specify_old_postcondition(); - #endif + specify_old_postcondition_except precondition(F const& f) { + BOOST_CONTRACT_SPECIFY_PRECONDITION_IMPL_ } /** @@ -364,18 +415,8 @@ public: allows to optionally specify postconditions. */ template - specify_postcondition_only 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(check_.release()); - #else - return specify_postcondition_only(); - #endif + specify_postcondition_except old(F const& f) { + BOOST_CONTRACT_SPECIFY_OLD_IMPL_ } /** @@ -398,51 +439,40 @@ public: not allow to specify any additional contract. */ template - 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 + 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::type> check_type; - - explicit specify_precondition_old_postcondition(check_type* check) : - check_(check) {} - - boost::contract::detail::auto_ptr check_; - #endif + BOOST_CONTRACT_SPECIFY_COND_CTOR_( + specify_precondition_old_postcondition_except, + boost::contract::detail::cond_with_post::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 - friend specify_precondition_old_postcondition<> public_function(); + friend specify_precondition_old_postcondition_except<> public_function(); template - friend specify_precondition_old_postcondition<> public_function(C*); + friend specify_precondition_old_postcondition_except<> public_function(C*); template - friend specify_precondition_old_postcondition<> public_function( + friend specify_precondition_old_postcondition_except<> public_function( virtual_*, C*); template - friend specify_precondition_old_postcondition public_function( + friend specify_precondition_old_postcondition_except public_function( virtual_*, VR&, C*); BOOST_CONTRACT_DETAIL_DECL_FRIEND_OVERRIDING_PUBLIC_FUNCTIONS_Z(1, diff --git a/include/boost/contract/core/virtual.hpp b/include/boost/contract/core/virtual.hpp index 26e6fc5..1b3d2d7 100644 --- a/include/boost/contract/core/virtual.hpp +++ b/include/boost/contract/core/virtual.hpp @@ -16,6 +16,9 @@ Facility to declare virtual public functions with contracts. #include #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS #include +#endif +#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_EXCEPTS) #include #include #include @@ -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 > old_inits_; std::stack > 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 */ }; diff --git a/include/boost/contract/destructor.hpp b/include/boost/contract/destructor.hpp index c6f74b8..ca92bf5 100644 --- a/include/boost/contract/destructor.hpp +++ b/include/boost/contract/destructor.hpp @@ -12,7 +12,7 @@ Program contracts for destructors. */ #include -#if !defined(BOOST_CONTRACT_NO_DESTRUCTORS) || \ +#if !defined(BOOST_CONTRACT_NO_DESTRUCTORS) || \ !defined(BOOST_CONTRACT_NO_PRECONDITIONS) #include #endif @@ -35,14 +35,14 @@ postconditions when the enclosing class has no invariants. run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}). */ template -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(obj)); #else - return specify_old_postcondition<>(); + return specify_old_postcondition_except<>(); #endif } diff --git a/include/boost/contract/detail/assert.hpp b/include/boost/contract/detail/assert.hpp index c696f5c..b72a0e4 100644 --- a/include/boost/contract/detail/assert.hpp +++ b/include/boost/contract/detail/assert.hpp @@ -10,13 +10,13 @@ #include #include +// 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 diff --git a/include/boost/contract/detail/check_guard.hpp b/include/boost/contract/detail/checking.hpp similarity index 80% rename from include/boost/contract/detail/check_guard.hpp rename to include/boost/contract/detail/checking.hpp index 489326a..d0743a8 100644 --- a/include/boost/contract/detail/check_guard.hpp +++ b/include/boost/contract/detail/checking.hpp @@ -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_; diff --git a/include/boost/contract/detail/condition/check_base.hpp b/include/boost/contract/detail/condition/check_base.hpp deleted file mode 100644 index 841dd8e..0000000 --- a/include/boost/contract/detail/condition/check_base.hpp +++ /dev/null @@ -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 -#include -#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - #include -#endif -#include -#include -#ifndef BOOST_CONTRACT_ON_MISSING_GUARD - #include -#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 - void set_pre(F const& f) { pre_ = f; } - #endif - - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - template - 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 pre_; // Use Boost.Function to also... - #endif - #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::function old_; // ...handle lambdas, binds, etc. - #endif -}; - -} } } // namespace - -#endif // #include guard - diff --git a/include/boost/contract/detail/condition/cond_base.hpp b/include/boost/contract/detail/condition/cond_base.hpp new file mode 100644 index 0000000..5f30529 --- /dev/null +++ b/include/boost/contract/detail/condition/cond_base.hpp @@ -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 +#include +#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_EXEPTS) + #include +#endif +#include +#include +#ifndef BOOST_CONTRACT_ON_MISSING_CHECK_DECL + #include +#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 + void set_pre(F const& f) { pre_ = f; } + #endif + + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + template + void set_old(F const& f) { old_ = f; } + #endif + + #ifndef BOOST_CONTRACT_NO_EXCEPTS + template + 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 pre_; + #endif + #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS + boost::function old_; + #endif + #ifndef BOOST_CONTRACT_NO_EXCEPTS + boost::function except_; + #endif +}; + +} } } // namespace + +#endif // #include guard + diff --git a/include/boost/contract/detail/condition/check_pre_post_inv.hpp b/include/boost/contract/detail/condition/cond_with_inv.hpp similarity index 90% rename from include/boost/contract/detail/condition/check_pre_post_inv.hpp rename to include/boost/contract/detail/condition/cond_with_inv.hpp index fef0f40..b09a7f0 100644 --- a/include/boost/contract/detail/condition/check_pre_post_inv.hpp +++ b/include/boost/contract/detail/condition/cond_with_inv.hpp @@ -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 #include -#include +#include #ifndef BOOST_CONTRACT_NO_INVARIANTS #include #include @@ -32,8 +32,8 @@ namespace boost { namespace contract { namespace detail { template -class check_pre_post_inv : public check_pre_post { // Non-copyable base. - #if !defined(BOOST_CONTRACT_NO_INVARIANTS) && \ +class cond_with_inv : public cond_with_post { // 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 { // 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(from) - #if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ + explicit cond_with_inv(boost::contract::from from, C* obj) : + cond_with_post(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 class HasFunc, template 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 }; diff --git a/include/boost/contract/detail/condition/check_pre_post.hpp b/include/boost/contract/detail/condition/cond_with_post.hpp similarity index 79% rename from include/boost/contract/detail/condition/check_pre_post.hpp rename to include/boost/contract/detail/condition/cond_with_post.hpp index ea7e09d..f5b3a28 100644 --- a/include/boost/contract/detail/condition/check_pre_post.hpp +++ b/include/boost/contract/detail/condition/cond_with_post.hpp @@ -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 #include -#include +#include #include #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS #include @@ -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 \ @@ -42,9 +42,9 @@ namespace boost { namespace contract { namespace detail { template -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 : 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 - BOOST_CONTRACT_DETAIL_CHECK_PRE_POST_DEF_( + BOOST_CONTRACT_DETAIL_COND_WITH_POST_DEF_( none, unused, void (), diff --git a/include/boost/contract/detail/condition/check_subcontracted_pre_post_inv.hpp b/include/boost/contract/detail/condition/cond_with_subcontracting.hpp similarity index 79% rename from include/boost/contract/detail/condition/check_subcontracted_pre_post_inv.hpp rename to include/boost/contract/detail/condition/cond_with_subcontracting.hpp index 9ba3773..0be0865 100644 --- a/include/boost/contract/detail/condition/check_subcontracted_pre_post_inv.hpp +++ b/include/boost/contract/detail/condition/cond_with_subcontracting.hpp @@ -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 -#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 #endif -#include +#include #include #include -#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 #include #include @@ -43,15 +45,17 @@ #include #endif #include -#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 #endif #ifndef BOOST_CONTRACT_NO_PRECONDITIONS #include #include #endif -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS +#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ + !defined(BOSOT_CONTRACT_NO_EXCEPTS) #include #include #include @@ -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 -{ - #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 +{ // 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 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(from, obj) + cond_with_inv(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(r); + check_virtual_post_with_result(r); } template typename boost::enable_if >::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 boost::disable_if >::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::value) return false; try { call_base(*this)(typename boost::mpl::front::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::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 void operator()(B*) { @@ -420,8 +437,7 @@ private: try { call(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, diff --git a/include/boost/contract/detail/decl.hpp b/include/boost/contract/detail/decl.hpp index db1ad9a..884d244 100644 --- a/include/boost/contract/detail/decl.hpp +++ b/include/boost/contract/detail/decl.hpp @@ -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 - class specify_precondition_old_postcondition; + class specify_precondition_old_postcondition_except; } } diff --git a/include/boost/contract/detail/inlined/core/exception.hpp b/include/boost/contract/detail/inlined/core/exception.hpp index b0d57e0..84e88d8 100644 --- a/include/boost/contract/detail/inlined/core/exception.hpp +++ b/include/boost/contract/detail/inlined/core/exception.hpp @@ -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 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 void default_from_handler(from) { default_handler(); } - #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; + from_failure_handler entry_inv_failure_handler = + &default_from_handler; + + #ifndef BOOST_CONTRACT_DISABLE_THREADS + boost::mutex exit_inv_failure_mutex; + #endif + from_failure_handler exit_inv_failure_handler = + &default_from_handler; #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; #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; + from_failure_handler except_failure_handler = + &default_from_handler; - #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; + failure_handler check_failure_handler = &default_handler; } // 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 diff --git a/include/boost/contract/detail/inlined/detail/check_guard.hpp b/include/boost/contract/detail/inlined/detail/checking.hpp similarity index 72% rename from include/boost/contract/detail/inlined/detail/check_guard.hpp rename to include/boost/contract/detail/inlined/detail/checking.hpp index c49829f..dcbf5ef 100644 --- a/include/boost/contract/detail/inlined/detail/check_guard.hpp +++ b/include/boost/contract/detail/inlined/detail/checking.hpp @@ -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 +#include #ifndef BOOST_CONTRACT_DISABLE_THREADS #include #endif namespace boost { namespace contract { namespace detail { -check_guard::check_guard() { +checking::checking() { #ifndef BOOST_CONTRACT_DISABLE_THREADS boost::lock_guard lock(mutex_); #endif checking_ = true; } -check_guard::~check_guard() { +checking::~checking() { #ifndef BOOST_CONTRACT_DISABLE_THREADS boost::lock_guard lock(mutex_); #endif checking_ = false; } -bool check_guard::checking() { +bool checking::already() { #ifndef BOOST_CONTRACT_DISABLE_THREADS boost::lock_guard 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 diff --git a/include/boost/contract/detail/operation/constructor.hpp b/include/boost/contract/detail/operation/constructor.hpp index c416be7..aa70fd6 100644 --- a/include/boost/contract/detail/operation/constructor.hpp +++ b/include/boost/contract/detail/operation/constructor.hpp @@ -9,14 +9,16 @@ #include #include -#include +#include #include -#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - #include +#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ + !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_EXCEPTS) + #include #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 #include #endif @@ -24,51 +26,60 @@ namespace boost { namespace contract { namespace detail { // Ctor subcontracting impl via C++ obj construction mechanism. -template -class constructor : - public check_pre_post_inv { // Non-copyable base. +template // Non-copyable base. +class constructor : public cond_with_inv { public: - explicit constructor(C* obj) : check_pre_post_inv( + explicit constructor(C* obj) : cond_with_inv( 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 }; diff --git a/include/boost/contract/detail/operation/destructor.hpp b/include/boost/contract/detail/operation/destructor.hpp index dc07e5d..32a386a 100644 --- a/include/boost/contract/detail/operation/destructor.hpp +++ b/include/boost/contract/detail/operation/destructor.hpp @@ -9,14 +9,16 @@ #include #include -#include +#include #include -#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - #include +#if !defined(BOOST_CONTRACT_NO_INVARIANTS) || \ + !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_EXCEPTS) + #include #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 #include #endif @@ -24,40 +26,42 @@ namespace boost { namespace contract { namespace detail { // Dtor subcontracting impl via C++ obj destruction mechanism. -template -class destructor : - public check_pre_post_inv { // Non-copyable base. +template // Non-copyable base. +class destructor : public cond_with_inv { public: - explicit destructor(C* obj) : check_pre_post_inv( + explicit destructor(C* obj) : cond_with_inv( 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 }; diff --git a/include/boost/contract/detail/operation/function.hpp b/include/boost/contract/detail/operation/function.hpp index 483933f..b97d5fe 100644 --- a/include/boost/contract/detail/operation/function.hpp +++ b/include/boost/contract/detail/operation/function.hpp @@ -9,12 +9,14 @@ #include #include -#include -#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ - !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) - #include +#include +#if !defined(BOOST_CONTRACT_NO_PRECONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_EXCEPTS) + #include #endif -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS +#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_EXCEPTS) #include #include #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 { // Non-copyable base. +class function : public cond_with_post { // Non-copyable base. public: - explicit function() : check_pre_post( + explicit function() : cond_with_post( 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 }; diff --git a/include/boost/contract/detail/operation/public_function.hpp b/include/boost/contract/detail/operation/public_function.hpp index dfcbff0..7a78bbb 100644 --- a/include/boost/contract/detail/operation/public_function.hpp +++ b/include/boost/contract/detail/operation/public_function.hpp @@ -10,19 +10,22 @@ #include #include #include -#include +#include #include #include -#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 + !defined(BOOST_CONTRACT_NO_EXCEPTS) + #include #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 #endif -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS +#if !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \ + !defined(BOOST_CONTRACT_NO_EXCEPTS) #include #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 diff --git a/include/boost/contract/detail/operation/public_static_function.hpp b/include/boost/contract/detail/operation/public_static_function.hpp index ba587a8..bf98553 100644 --- a/include/boost/contract/detail/operation/public_static_function.hpp +++ b/include/boost/contract/detail/operation/public_static_function.hpp @@ -9,78 +9,85 @@ #include #include -#include +#include #include -#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 + !defined(BOOST_CONTRACT_NO_EXCEPTS) + #include #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 -#endif -#ifndef BOOST_CONTRACT_NO_POSTCONDITIONS #include #endif namespace boost { namespace contract { namespace detail { // No subcontracting because static so no obj and no substitution principle. -template -class public_static_function : - public check_pre_post_inv { // Non-copyable base. +template // Non-copyable base. +class public_static_function : public cond_with_inv { public: - explicit public_static_function() : - check_pre_post_inv(boost::contract::from_function, - /* obj = */ 0) - {} + explicit public_static_function() : cond_with_inv( + 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 }; diff --git a/include/boost/contract/function.hpp b/include/boost/contract/function.hpp index 853b73f..ddeb8c4 100644 --- a/include/boost/contract/function.hpp +++ b/include/boost/contract/function.hpp @@ -14,7 +14,7 @@ Program contracts for non-member, private, and protected functions. */ #include -#if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \ +#if !defined(BOOST_CONTRACT_NO_FUNCTIONS) || \ !defined(BOOST_CONTRACT_NO_INVARIANTS) #include #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 } diff --git a/include/boost/contract/old.hpp b/include/boost/contract/old.hpp index 8cca47e..cb395a7 100644 --- a/include/boost/contract/old.hpp +++ b/include/boost/contract/old.hpp @@ -12,7 +12,7 @@ Facilities to support old values. */ #include -#include +#include #include #include #include @@ -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 diff --git a/include/boost/contract/public_function.hpp b/include/boost/contract/public_function.hpp index a94c2fa..281c1bb 100644 --- a/include/boost/contract/public_function.hpp +++ b/include/boost/contract/public_function.hpp @@ -74,12 +74,12 @@ invariants. run-time error, see @RefMacro{BOOST_CONTRACT_ON_MISSING_GUARD}). */ template -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()); #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 -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 - 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 - specify_precondition_old_postcondition public_function( - virtual_* v, VirtualResult& r, Class* obj); + specify_precondition_old_postcondition_except + 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::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 - 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 - specify_precondition_old_postcondition public_function( - virtual_* v, VirtualResult& r, F f, Class* obj, Args&... args); + specify_precondition_old_postcondition_except + 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) diff --git a/src/contract.cpp b/src/contract.cpp index fb7d55a..39a7040 100644 --- a/src/contract.cpp +++ b/src/contract.cpp @@ -12,5 +12,5 @@ #define BOOST_CONTRACT_DETAIL_SOURCE #include -#include +#include diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 82723e4..df1322c 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -6,8 +6,7 @@ subdir-usage ; -test-suite constructor -: +test-suite constructor : [ subdir-run-with-no constructor : decl_pre_all ] [ subdir-run-with-no constructor : decl_pre_ends ] [ subdir-run-with-no constructor : decl_pre_mid ] @@ -45,8 +44,7 @@ test-suite constructor [ subdir-compile-fail constructor : pre_error ] ; -test-suite destructor -: +test-suite destructor : # No decl_pre_... for destructors. [ subdir-run-with-no destructor : decl_post_all ] @@ -81,8 +79,7 @@ test-suite destructor [ subdir-compile-fail destructor : pre_error ] ; -test-suite public_function -: +test-suite public_function : [ subdir-run-with-no public_function : decl_pre_all ] [ subdir-run-with-no public_function : decl_pre_ends ] [ subdir-run-with-no public_function : decl_pre_mid ] @@ -153,8 +150,7 @@ test-suite public_function [ subdir-run-with-no public_function : static_no_contracts ] ; -test-suite invariant -: +test-suite invariant : [ subdir-run-with-no invariant : decl_static_cv_const ] [ subdir-run-with-no invariant : decl_static_cv ] [ subdir-run-with-no invariant : decl_cv_const ] @@ -181,8 +177,7 @@ test-suite invariant [ subdir-run-with-no invariant : volatile_permissive ] ; -test-suite function -: +test-suite function : [ subdir-run-with-no function : decl_pre_all ] [ subdir-run-with-no function : decl_pre_none ] @@ -196,36 +191,32 @@ test-suite function [ subdir-run-with-no function : old_throw ] ; -test-suite check -: +test-suite check : [ subdir-run-with-no check : decl_class ] [ subdir-run-with-no check : decl_macro ] ; -test-suite result -: +test-suite result : [ subdir-run-with-no result : mixed_optional ] [ subdir-run-with-no result : mixed_optional_ref ] [ subdir-compile-fail result : type_mismatch_error ] ; -test-suite old -: +test-suite old : [ subdir-run-with-no old : auto ] [ subdir-run-with-no old : no_macros ] - [ subdir-run-with-no old : no_macros_noncopyable ] + [ subdir-run-with-no old : no_macros_if_copyable ] [ subdir-compile-fail old : no_make_old_error ] - [ subdir-compile-fail old : no_make_old_noncopyable_error ] + [ subdir-compile-fail old : no_make_old_if_copyable_error ] - [ subdir-run-with-no old : noncopyable ] - [ subdir-compile-fail old : noncopyable_error ] + [ subdir-run-with-no old : if_copyable ] + [ subdir-compile-fail old : if_copyable_error ] ; -test-suite disable -: +test-suite disable : [ subdir-run-with-no disable : prog ] [ subdir-run-with-no disable : prog_pre_disable_nothing ] @@ -236,27 +227,15 @@ test-suite disable [ subdir-run-with-no disable : lib_ab : disable-lib_a disable-lib_b ] - [ - subdir-lib disable : lib_x - : - shared:BOOST_CONTRACT_TEST_LIB_X_DYN_LINK - # Test contracts in .cpp so never post (as NO_POST here). - BOOST_CONTRACT_NO_POSTCONDITIONS - ] - [ - subdir-lib disable : lib_y - : - disable-lib_x - shared:BOOST_CONTRACT_TEST_LIB_Y_DYN_LINK - # Test contracts in .hpp so can have post (even if NO_POST here). - BOOST_CONTRACT_NO_POSTCONDITIONS - ] + [ subdir-lib disable : lib_x : + shared:BOOST_CONTRACT_TEST_LIB_X_DYN_LINK ] + [ subdir-lib disable : lib_y : disable-lib_x + shared:BOOST_CONTRACT_TEST_LIB_Y_DYN_LINK ] [ subdir-run-with-no disable : lib_xy : disable-lib_x disable-lib_y ] ; -test-suite specify -: +test-suite specify : [ subdir-run-with-no specify : pre_old_post ] [ subdir-run-with-no specify : pre_old ] [ subdir-run-with-no specify : old_post ] @@ -266,15 +245,14 @@ test-suite specify [ subdir-run-with-no specify : post ] [ subdir-run-with-no specify : nothing ] - [ subdir-run-with-no specify : no_guard ] + [ subdir-run-with-no specify : missing_check_decl ] [ subdir-compile-fail specify : old_pre_error ] [ subdir-compile-fail specify : post_old_error ] [ subdir-compile-fail specify : post_pre_error ] ; -test-suite call_if -: +test-suite call_if : [ subdir-run call_if : true_ ] [ subdir-run call_if : false_ ] @@ -286,14 +264,9 @@ test-suite call_if [ subdir-run-with-no call_if : condition_if ] [ subdir-compile-fail call_if : no_condition_if_error ] ; - -# C++14 supported only by Clang... so in its own test-suite and explicit. -test-suite call_if-cxx14 -: +test-suite call_if-cxx14 : # Requires C++14. [ subdir-run call_if : equal_to_cxx14 : clang:-std=c++1y ] - [ subdir-run call_if : advance_cxx14 : - clang:-std=c++1y ] ; explicit call_if-cxx14 ; diff --git a/test/call_if/condition_if.cpp b/test/call_if/condition_if.cpp index 698b824..1ce284d 100644 --- a/test/call_if/condition_if.cpp +++ b/test/call_if/condition_if.cpp @@ -7,7 +7,7 @@ // Test assertions skipped when operations to check them missing (e.g., `==`). #include -#include +#include #include #include #include @@ -19,19 +19,19 @@ unsigned equal_skips; template -void push_back(std::vector& vect, T const& val) { - boost::contract::guard c = boost::contract::function() +void push_back(std::vector& vect, T const& value) { + boost::contract::check c = boost::contract::function() .postcondition([&] { BOOST_CONTRACT_ASSERT( boost::contract::condition_if >( boost::bind(std::equal_to(), boost::cref(vect.back()), - boost::cref(val)) + boost::cref(value)) ) ); if(!boost::has_equal_to::value) ++equal_skips; }) ; - vect.push_back(val); + vect.push_back(value); } struct j { // Type without operator==. diff --git a/test/call_if/no_condition_if_error.cpp b/test/call_if/no_condition_if_error.cpp index 40dacd8..0573c70 100644 --- a/test/call_if/no_condition_if_error.cpp +++ b/test/call_if/no_condition_if_error.cpp @@ -7,18 +7,18 @@ // Test assertion error when operations to check them missing (e.g., `==`). #include -#include +#include #include #include template -void push_back(std::vector& vect, T const& val) { - boost::contract::guard c = boost::contract::function() +void push_back(std::vector& vect, T const& value) { + boost::contract::check c = boost::contract::function() .postcondition([&] { - BOOST_CONTRACT_ASSERT(vect.back() == val); // Error (j has no ==). + BOOST_CONTRACT_ASSERT(vect.back() == value); // Error (j has no ==). }) ; - vect.push_back(val); + vect.push_back(value); } struct j { // Type without operator==. diff --git a/test/constructor/access.cpp b/test/constructor/access.cpp index ce20242..b3fca68 100644 --- a/test/constructor/access.cpp +++ b/test/constructor/access.cpp @@ -9,7 +9,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include @@ -31,7 +31,7 @@ public: b() : boost::contract::constructor_precondition([] { out << "b::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old([] { out << "b::ctor::old" << std::endl; }) .postcondition([] { out << "b::ctor::post" << std::endl; }) ; @@ -57,7 +57,7 @@ public: a() : boost::contract::constructor_precondition([] { out << "a::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old([] { out << "a::ctor::old" << std::endl; }) .postcondition([] { out << "a::ctor::post" << std::endl; }) ; diff --git a/test/constructor/body_throw.cpp b/test/constructor/body_throw.cpp index 8434d15..b839883 100644 --- a/test/constructor/body_throw.cpp +++ b/test/constructor/body_throw.cpp @@ -9,7 +9,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include @@ -26,13 +26,14 @@ struct c void invariant() const { out << "c::inv" << std::endl; } c() : - boost::contract::constructor_precondition([&] { + boost::contract::constructor_precondition([] { out << "c::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) - .old([&] { out << "c::ctor::old" << std::endl; }) - .postcondition([&] { out << "c::ctor::post" << std::endl; }) + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "c::ctor::old" << std::endl; }) + .postcondition([] { out << "c::ctor::post" << std::endl; }) + .except([] { out << "c::ctor::except" << std::endl; }) ; out << "c::ctor::body" << std::endl; // Do not throw (from inheritance root). @@ -56,9 +57,10 @@ struct b out << "b::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) - .old([&] { out << "b::ctor::old" << std::endl; }) - .postcondition([&] { out << "b::ctor::post" << std::endl; }) + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "b::ctor::old" << std::endl; }) + .postcondition([] { out << "b::ctor::post" << std::endl; }) + .except([] { out << "b::ctor::except" << std::endl; }) ; out << "b::ctor::body" << std::endl; throw b::err(); // Test body throws (from inheritance mid branch). @@ -76,13 +78,14 @@ struct a void invariant() const { out << "a::inv" << std::endl; } a() : - boost::contract::constructor_precondition([&] { + boost::contract::constructor_precondition([] { out << "a::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) - .old([&] { out << "a::ctor::old" << std::endl; }) - .postcondition([&] { out << "a::ctor::post" << std::endl; }) + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "a::ctor::old" << std::endl; }) + .postcondition([] { out << "a::ctor::post" << std::endl; }) + .except([] { out << "a::ctor::except" << std::endl; }) ; out << "a::ctor::body" << std::endl; // Do not throw (from inheritance leaf). @@ -126,8 +129,12 @@ int main() { << "b::ctor::old" << std::endl #endif << "b::ctor::body" << std::endl // Test this threw... + // ... so check only following after (no post, no a ctor, etc.). #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - << "b::static_inv" << std::endl // ... so check only this after. + << "b::static_inv" << std::endl + #endif + #ifndef BOOST_CONTRACT_NO_EXCETPS + << "b::ctor::except" << std::endl #endif ; BOOST_TEST(out.eq(ok.str())); diff --git a/test/constructor/contracts.cpp b/test/constructor/contracts.cpp index 65e02ae..7463ce7 100644 --- a/test/constructor/contracts.cpp +++ b/test/constructor/contracts.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -54,11 +54,11 @@ struct t { boost::contract::old_ptr old_z; boost::contract::old_ptr old_l = - BOOST_CONTRACT_OLDOF(l_type::eval(l)); - boost::contract::guard c = boost::contract::constructor(this) + BOOST_CONTRACT_OLD(l_type::eval(l)); + boost::contract::check c = boost::contract::constructor(this) .old([&] { out << Id << "::ctor::old" << std::endl; - old_z = BOOST_CONTRACT_OLDOF(z_type::eval(z)); + old_z = BOOST_CONTRACT_OLD(z_type::eval(z)); }) .postcondition([&] { out << Id << "::ctor::post" << std::endl; @@ -117,12 +117,12 @@ struct c t<'d'>(dz), t<'p'>(pz), t<'q'>(qz), t<'e'>(ez) { boost::contract::old_ptr old_y = - BOOST_CONTRACT_OLDOF(y_type::eval(y)); + BOOST_CONTRACT_OLD(y_type::eval(y)); boost::contract::old_ptr old_m; - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old([&] { out << "c::ctor::old" << std::endl; - old_m = BOOST_CONTRACT_OLDOF(m_type::eval(m)); + old_m = BOOST_CONTRACT_OLD(m_type::eval(m)); }) .postcondition([&] { out << "c::ctor::post" << std::endl; @@ -194,11 +194,11 @@ struct a { boost::contract::old_ptr old_x; boost::contract::old_ptr old_n = - BOOST_CONTRACT_OLDOF(n_type::eval(n)); - boost::contract::guard c = boost::contract::constructor(this) + BOOST_CONTRACT_OLD(n_type::eval(n)); + boost::contract::check c = boost::contract::constructor(this) .old([&] { out << "a::ctor::old" << std::endl; - old_x = BOOST_CONTRACT_OLDOF(x_type::eval(x)); + old_x = BOOST_CONTRACT_OLD(x_type::eval(x)); }) .postcondition([&] { out << "a::ctor::post" << std::endl; diff --git a/test/constructor/decl.hpp b/test/constructor/decl.hpp index b4b12fc..5368c31 100644 --- a/test/constructor/decl.hpp +++ b/test/constructor/decl.hpp @@ -12,7 +12,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include boost::contract::test::detail::oteststream out; @@ -49,7 +49,7 @@ struct c }) #endif { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old([] { out << "c::ctor::old" << std::endl; }) #ifndef BOOST_CONTRACT_TEST_NO_C_POST .postcondition([] { @@ -101,7 +101,7 @@ struct b }) #endif { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old([] { out << "b::ctor::old" << std::endl; }) #ifndef BOOST_CONTRACT_TEST_NO_B_POST .postcondition([] { @@ -153,7 +153,7 @@ struct a }) #endif { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old([] { out << "a::ctor::old" << std::endl; }) #ifndef BOOST_CONTRACT_TEST_NO_A_POST .postcondition([] { diff --git a/test/constructor/ifdef_contracts.cpp b/test/constructor/ifdef_contracts.cpp index 29e2363..2df0e31 100644 --- a/test/constructor/ifdef_contracts.cpp +++ b/test/constructor/ifdef_contracts.cpp @@ -10,7 +10,7 @@ #include #include // Outside #if below for ctor pre. #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - #include + #include #include #endif #include @@ -36,10 +36,10 @@ struct b #endif { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(x); #endif #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS .old([] { out << "b::f::old" << std::endl; }) .postcondition([] { out << "b::ctor::post" << std::endl; }) @@ -70,10 +70,10 @@ struct a : b(x) { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(x); #endif #ifndef BOOST_CONTRACT_NO_CONSTRUCTORS - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS .old([] { out << "a::f::old" << std::endl; }) .postcondition([] { out << "a::ctor::post" << std::endl; }) diff --git a/test/constructor/old_throw.cpp b/test/constructor/old_throw.cpp index 7393f1a..12baa84 100644 --- a/test/constructor/old_throw.cpp +++ b/test/constructor/old_throw.cpp @@ -9,7 +9,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include @@ -26,13 +26,13 @@ struct c void invariant() const { out << "c::inv" << std::endl; } c() : - boost::contract::constructor_precondition([&] { + boost::contract::constructor_precondition([] { out << "c::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) - .old([&] { out << "c::ctor::old" << std::endl; }) - .postcondition([&] { out << "c::ctor::post" << std::endl; }) + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "c::ctor::old" << std::endl; }) + .postcondition([] { out << "c::ctor::post" << std::endl; }) ; out << "c::ctor::body" << std::endl; // Do not throw (from inheritance root). @@ -56,12 +56,12 @@ struct b out << "b::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) - .old([&] { + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "b::ctor::old" << std::endl; throw b::err(); // Test .old() throws (from mid branch). }) - .postcondition([&] { out << "b::ctor::post" << std::endl; }) + .postcondition([] { out << "b::ctor::post" << std::endl; }) ; out << "b::ctor::body" << std::endl; } @@ -78,13 +78,13 @@ struct a void invariant() const { out << "a::inv" << std::endl; } a() : - boost::contract::constructor_precondition([&] { + boost::contract::constructor_precondition([] { out << "a::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) - .old([&] { out << "a::ctor::old" << std::endl; }) - .postcondition([&] { out << "a::ctor::post" << std::endl; }) + boost::contract::check c = boost::contract::constructor(this) + .old([] { out << "a::ctor::old" << std::endl; }) + .postcondition([] { out << "a::ctor::post" << std::endl; }) ; out << "a::ctor::body" << std::endl; // Do not throw (from inheritance leaf). diff --git a/test/constructor/pre_error.cpp b/test/constructor/pre_error.cpp index bbabd74..8c6db68 100644 --- a/test/constructor/pre_error.cpp +++ b/test/constructor/pre_error.cpp @@ -7,11 +7,11 @@ // Test constructor cannot use `.precondition(...)`. #include -#include +#include struct a { a() { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .precondition([] {}) // Error (must use constructor_precondition). ; } diff --git a/test/destructor/access.cpp b/test/destructor/access.cpp index 6952260..55dade0 100644 --- a/test/destructor/access.cpp +++ b/test/destructor/access.cpp @@ -9,7 +9,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include @@ -23,7 +23,7 @@ class b { public: virtual ~b() { - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .old([] { out << "b::dtor::old" << std::endl; }) .postcondition([] { out << "b::dtor::post" << std::endl; }) ; @@ -47,7 +47,7 @@ class a public: virtual ~a() { - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .old([] { out << "a::dtor::old" << std::endl; }) .postcondition([] { out << "a::dtor::post" << std::endl; }) ; diff --git a/test/destructor/body_throw.cpp b/test/destructor/body_throw.cpp index 9199212..809b5a8 100644 --- a/test/destructor/body_throw.cpp +++ b/test/destructor/body_throw.cpp @@ -9,7 +9,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include #include @@ -21,9 +21,10 @@ struct c { void invariant() const { out << "c::inv" << std::endl; } ~c() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { out << "c::dtor::old" << std::endl; }) + boost::contract::check c = boost::contract::destructor(this) + .old([] { out << "c::dtor::old" << std::endl; }) .postcondition([] { out << "c::dtor::post" << std::endl; }) + .except([] { out << "c::dtor::except" << std::endl; }) ; out << "c::dtor::body" << std::endl; // Do not throw (from inheritance root). @@ -43,9 +44,10 @@ struct b struct err {}; ~b() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { out << "b::dtor::old" << std::endl; }) + boost::contract::check c = boost::contract::destructor(this) + .old([] { out << "b::dtor::old" << std::endl; }) .postcondition([] { out << "b::dtor::post" << std::endl; }) + .except([] { out << "b::dtor::except" << std::endl; }) ; out << "b::dtor::body" << std::endl; throw b::err(); // Test body throw (from inheritance mid branch). @@ -63,9 +65,10 @@ struct a void invariant() const { out << "a::inv" << std::endl; } ~a() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { out << "a::dtor::old" << std::endl; }) + boost::contract::check c = boost::contract::destructor(this) + .old([] { out << "a::dtor::old" << std::endl; }) .postcondition([] { out << "a::dtor::post" << std::endl; }) + .except([] { out << "a::dtor::except" << std::endl; }) ; out << "a::dtor::body" << std::endl; // Do not throw (from inheritance leaf). @@ -107,11 +110,14 @@ int main() { << "b::dtor::old" << std::endl #endif << "b::dtor::body" << std::endl // Test this threw. - // Test b not destructed (so both static_inv and inv, but no post). + // Test b not destructed (so static_inv, inv, and except, no post). #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS << "b::static_inv" << std::endl << "b::inv" << std::endl #endif + #ifndef BOOST_CONTRACT_NO_EXCEPTS + << "b::dtor::except" << std::endl + #endif #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS << "c::static_inv" << std::endl @@ -121,11 +127,14 @@ int main() { << "c::dtor::old" << std::endl #endif << "c::dtor::body" << std::endl - // Test c not destructed (so both static_inv and inv, but no post). + // Test c not destructed (so static_inv, inv, and except, no post). #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS << "c::static_inv" << std::endl << "c::inv" << std::endl #endif + #ifndef BOOST_CONTRACT_NO_EXCEPTS + << "c::dtor::except" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/destructor/contracts.cpp b/test/destructor/contracts.cpp index 179bea4..839adf7 100644 --- a/test/destructor/contracts.cpp +++ b/test/destructor/contracts.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -39,10 +39,10 @@ struct t { virtual ~t() { boost::contract::old_ptr old_l; - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .old([&] { out << Id << "::dtor::old" << std::endl; - old_l = BOOST_CONTRACT_OLDOF(l_type::eval(l)); + old_l = BOOST_CONTRACT_OLD(l_type::eval(l)); }) .postcondition([&old_l] { out << Id << "::dtor::post" << std::endl; @@ -87,9 +87,9 @@ struct c virtual ~c() { boost::contract::old_ptr old_m = - BOOST_CONTRACT_OLDOF(m_type::eval(m)); - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { + BOOST_CONTRACT_OLD(m_type::eval(m)); + boost::contract::check c = boost::contract::destructor(this) + .old([] { out << "c::dtor::old" << std::endl; // Test old-of assignment above instead. }) @@ -142,10 +142,10 @@ struct a virtual ~a() { boost::contract::old_ptr old_n; - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .old([&] { out << "a::dtor::old" << std::endl; - old_n = BOOST_CONTRACT_OLDOF(n_type::eval(n)); + old_n = BOOST_CONTRACT_OLD(n_type::eval(n)); }) .postcondition([&old_n] { out << "a::dtor::post" << std::endl; diff --git a/test/destructor/decl.hpp b/test/destructor/decl.hpp index 6317e6f..5cf7534 100644 --- a/test/destructor/decl.hpp +++ b/test/destructor/decl.hpp @@ -12,7 +12,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include @@ -39,7 +39,7 @@ struct c { #endif virtual ~c() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) #ifdef BOOST_CONTRACT_TEST_NO_C_PRE #error "destructors cannot have preconditions" #endif @@ -82,7 +82,7 @@ struct b #endif virtual ~b() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) #ifdef BOOST_CONTRACT_TEST_NO_B_PRE #error "destructors cannot have preconditions" #endif @@ -125,7 +125,7 @@ struct a #endif virtual ~a() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) #ifdef BOOST_CONTRACT_TEST_NO_A_PRE #error "destructors cannot have preconditions" #endif diff --git a/test/destructor/ifdef_contracts.cpp b/test/destructor/ifdef_contracts.cpp index 8bf1bbb..da5d984 100644 --- a/test/destructor/ifdef_contracts.cpp +++ b/test/destructor/ifdef_contracts.cpp @@ -10,7 +10,7 @@ #include #ifndef BOOST_CONTRACT_NO_DESTRUCTORS #include - #include + #include #include #endif #include @@ -26,10 +26,10 @@ struct b { virtual ~b() { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_y = BOOST_CONTRACT_OLDOF(y); + boost::contract::old_ptr old_y = BOOST_CONTRACT_OLD(y); #endif #ifndef BOOST_CONTRACT_NO_DESTRUCTORS - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS .old([] { out << "b::dtor::old" << std::endl; }) .postcondition([] { out << "b::dtor::post" << std::endl; }) @@ -51,10 +51,10 @@ struct a : public b { virtual ~a() { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(x); #endif #ifndef BOOST_CONTRACT_NO_DESTRUCTORS - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS .old([] { out << "a::dtor::old" << std::endl; }) .postcondition([] { out << "a::dtor::post" << std::endl; }) diff --git a/test/destructor/old_throw.cpp b/test/destructor/old_throw.cpp index 009b506..926ac85 100644 --- a/test/destructor/old_throw.cpp +++ b/test/destructor/old_throw.cpp @@ -9,7 +9,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include #include @@ -21,8 +21,8 @@ struct c { void invariant() const { out << "c::inv" << std::endl; } ~c() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { out << "c::dtor::old" << std::endl; }) + boost::contract::check c = boost::contract::destructor(this) + .old([] { out << "c::dtor::old" << std::endl; }) .postcondition([] { out << "c::dtor::post" << std::endl; }) ; out << "c::dtor::body" << std::endl; @@ -43,8 +43,8 @@ struct b struct err {}; ~b() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { + boost::contract::check c = boost::contract::destructor(this) + .old([] { out << "b::dtor::old" << std::endl; throw b::err(); // Test .old() throw (from mid branch). }) @@ -65,8 +65,8 @@ struct a void invariant() const { out << "a::inv" << std::endl; } ~a() BOOST_NOEXCEPT_IF(false) { - boost::contract::guard c = boost::contract::destructor(this) - .old([&] { out << "a::dtor::old" << std::endl; }) + boost::contract::check c = boost::contract::destructor(this) + .old([] { out << "a::dtor::old" << std::endl; }) .postcondition([] { out << "a::dtor::post" << std::endl; }) ; out << "a::dtor::body" << std::endl; diff --git a/test/destructor/pre_error.cpp b/test/destructor/pre_error.cpp index b9f5bdb..ca087b5 100644 --- a/test/destructor/pre_error.cpp +++ b/test/destructor/pre_error.cpp @@ -7,11 +7,11 @@ // Test destructor cannot use `.precondition(...)`. #include -#include +#include struct a { ~a() { - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .precondition([] {}) // Error (no dtor func arg so never pre). ; } diff --git a/test/disable/lib_a_inlined.hpp b/test/disable/lib_a_inlined.hpp index 5727fb9..7486e3d 100644 --- a/test/disable/lib_a_inlined.hpp +++ b/test/disable/lib_a_inlined.hpp @@ -12,7 +12,7 @@ #include "lib_a.hpp" #include #include -#include +#include #include BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_STR_DEF(out) @@ -22,11 +22,11 @@ void a::invariant() const { out("a::inv\n"); } int a::f(x_type& x) { int result; - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF( + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD( x_type::eval(x)); - boost::contract::guard c = boost::contract::public_function(this) - .precondition([&] { out("a::f::pre\n"); }) - .old([&] { out("a::f::old\n"); }) + boost::contract::check c = boost::contract::public_function(this) + .precondition([] { out("a::f::pre\n"); }) + .old([] { out("a::f::old\n"); }) .postcondition([&] { out("a::f::post\n"); BOOST_CONTRACT_ASSERT(x.value == -old_x->value); @@ -65,7 +65,7 @@ void a::disable_inv_failure() { } void a::disable_failure() { - boost::contract::set_failure([] (boost::contract::from) + boost::contract::set_specification_failure([] (boost::contract::from) { out("a::failure\n"); }); } diff --git a/test/disable/lib_b_inlined.hpp b/test/disable/lib_b_inlined.hpp index 04a7dc6..3640520 100644 --- a/test/disable/lib_b_inlined.hpp +++ b/test/disable/lib_b_inlined.hpp @@ -12,7 +12,7 @@ #include "lib_b.hpp" #include "lib_a.hpp" #include -#include +#include #include bool call_f() { @@ -25,7 +25,7 @@ void b::static_invariant() { out("b::static_inv\n"); } void b::invariant() const { out("b::inv\n"); } void b::g() { - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([&] { out("b::g::pre\n"); BOOST_CONTRACT_ASSERT(call_f()); diff --git a/test/disable/lib_x.cpp b/test/disable/lib_x.cpp index a884218..30889f2 100644 --- a/test/disable/lib_x.cpp +++ b/test/disable/lib_x.cpp @@ -6,15 +6,19 @@ // Test contracts in .cpp so never has post (because NO_POST in its Jamfile). +// Test contracts in .cpp so never post (as NO_POST/EXCEPTS here). +#define BOOST_CONTRACT_NO_POSTCONDITIONS +#define BOOST_CONTRACT_NO_EXCEPTS + #define BOOST_CONTRACT_TEST_LIB_X_SOURCE #include "lib_x.hpp" #include -#include +#include BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_STR_DEF(out) void x() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out("x::pre\n"); }) .old([] { out("x::old\n"); }) .postcondition([] { out("x::post\n"); }) diff --git a/test/disable/lib_xy.cpp b/test/disable/lib_xy.cpp index a3344db..0e42767 100644 --- a/test/disable/lib_xy.cpp +++ b/test/disable/lib_xy.cpp @@ -9,12 +9,12 @@ #include "lib_x.hpp" #include "lib_y.hpp" #include -#include +#include #include #include void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out("f::pre\n"); }) .old([] { out("f::old\n"); }) .postcondition([] { out("f::post\n"); }) diff --git a/test/disable/lib_y.cpp b/test/disable/lib_y.cpp index 700c6ad..ce7a868 100644 --- a/test/disable/lib_y.cpp +++ b/test/disable/lib_y.cpp @@ -6,6 +6,10 @@ // Test contracts in .hpp so can have post (even if NO_POST in its Jamfile). +// Test contracts in .hpp so have post (even if NO_POST/EXPETS here). +#define BOOST_CONTRACT_NO_POSTCONDITIONS +#define BOOST_CONTRACT_NO_EXCEPTS + #define BOOST_CONTRACT_TEST_LIB_Y_SOURCE #include "lib_y.hpp" diff --git a/test/disable/lib_y.hpp b/test/disable/lib_y.hpp index ff95c98..85aa2e0 100644 --- a/test/disable/lib_y.hpp +++ b/test/disable/lib_y.hpp @@ -11,7 +11,7 @@ #include "lib_x.hpp" #include -#include +#include #include #ifdef BOOST_CONTRACT_TEST_LIB_Y_DYN_LINK @@ -29,7 +29,7 @@ namespace lib_y_ { // Internal namepsace. } inline void y() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out("y::pre\n"); }) .old([] { out("y::old\n"); }) .postcondition([] { out("y::post\n"); }) diff --git a/test/function/body_throw.cpp b/test/function/body_throw.cpp index cda89a3..df67134 100644 --- a/test/function/body_throw.cpp +++ b/test/function/body_throw.cpp @@ -8,7 +8,7 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include @@ -17,10 +17,11 @@ boost::contract::test::detail::oteststream out; struct err {}; void f() { - boost::contract::guard c = boost::contract::function() - .precondition([&] { out << "f::pre" << std::endl; }) - .old([&] { out << "f::old" << std::endl; }) - .postcondition([&] { out << "f::post" << std::endl; }) + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .old([] { out << "f::old" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) + .except([] { out << "f::except" << std::endl; }) ; out << "f::body" << std::endl; throw err(); // Test body throws. @@ -42,6 +43,9 @@ int main() { << "f::old" << std::endl #endif << "f::body" << std::endl // Test this threw. + #ifndef BOOST_CONTRACT_NO_EXCEPTS + << "f::except" << std::endl; + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/function/contracts.cpp b/test/function/contracts.cpp index a4c587c..62134b9 100644 --- a/test/function/contracts.cpp +++ b/test/function/contracts.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -24,16 +24,16 @@ struct y_tag; typedef boost::contract::test::detail::counter y_type; bool swap(x_type& x, y_type& y) { bool result; boost::contract::old_ptr old_x = - BOOST_CONTRACT_OLDOF(x_type::eval(x)); + BOOST_CONTRACT_OLD(x_type::eval(x)); boost::contract::old_ptr old_y; - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { out << "swap::pre" << std::endl; BOOST_CONTRACT_ASSERT(x.value != y.value); }) .old([&] { out << "swap::old" << std::endl; - old_y = BOOST_CONTRACT_OLDOF(y_type::eval(y)); + old_y = BOOST_CONTRACT_OLD(y_type::eval(y)); }) .postcondition([&] { out << "swap::post" << std::endl; diff --git a/test/function/decl.hpp b/test/function/decl.hpp index bee61aa..b43c977 100644 --- a/test/function/decl.hpp +++ b/test/function/decl.hpp @@ -11,16 +11,16 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include boost::contract::test::detail::oteststream out; bool f_pre = true, f_post = true; void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() #ifndef BOOST_CONTRACT_TEST_NO_F_PRE - .precondition([&] { + .precondition([] { out << "f::pre" << std::endl; BOOST_CONTRACT_ASSERT(f_pre); }) diff --git a/test/function/ifdef_contracts.cpp b/test/function/ifdef_contracts.cpp index 2bd4426..c8db1ee 100644 --- a/test/function/ifdef_contracts.cpp +++ b/test/function/ifdef_contracts.cpp @@ -10,7 +10,7 @@ #include #ifndef BOOST_CONTRACT_NO_FUNCTIONS #include - #include + #include #include #endif #include @@ -20,10 +20,10 @@ boost::contract::test::detail::oteststream out; void f(int x) { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(x); #endif #ifndef BOOST_CONTRACT_NO_FUNCTIONS - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() #ifndef BOOST_CONTRACT_NO_PRECONDITIONS .precondition([] { out << "f::pre" << std::endl; }) #endif diff --git a/test/function/old_throw.cpp b/test/function/old_throw.cpp index d3654fc..f97d416 100644 --- a/test/function/old_throw.cpp +++ b/test/function/old_throw.cpp @@ -8,7 +8,7 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include @@ -17,13 +17,13 @@ boost::contract::test::detail::oteststream out; struct err {}; void f() { - boost::contract::guard c = boost::contract::function() - .precondition([&] { out << "f::pre" << std::endl; }) - .old([&] { + boost::contract::check c = boost::contract::function() + .precondition([] { out << "f::pre" << std::endl; }) + .old([] { out << "f::old" << std::endl; throw err(); // Test .old() throws. }) - .postcondition([&] { out << "f::post" << std::endl; }) + .postcondition([] { out << "f::post" << std::endl; }) ; out << "f::body" << std::endl; } diff --git a/test/invariant/decl.hpp b/test/invariant/decl.hpp index ee36d48..55f8b4a 100644 --- a/test/invariant/decl.hpp +++ b/test/invariant/decl.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -37,7 +37,7 @@ struct b : private boost::contract::constructor_precondition { b() : boost::contract::constructor_precondition([] { out << "b::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old([] { out << "b::ctor::old" << std::endl; }) .postcondition([] { out << "b::ctor::post" << std::endl; }) ; @@ -45,7 +45,7 @@ struct b : private boost::contract::constructor_precondition { } virtual ~b() { - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .old([] { out << "b::dtor::old" << std::endl; }) .postcondition([] { out << "b::dtor::post" << std::endl; }) ; @@ -53,7 +53,7 @@ struct b : private boost::contract::constructor_precondition { } virtual void f(char x, boost::contract::virtual_* v = 0) volatile { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { out << "b::f::volatile_pre" << std::endl; BOOST_CONTRACT_ASSERT(x == 'b'); @@ -65,7 +65,7 @@ struct b : private boost::contract::constructor_precondition { } virtual void f(char x, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { out << "b::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(x == 'b'); @@ -97,7 +97,7 @@ struct a a() : boost::contract::constructor_precondition([] { out << "a::ctor::pre" << std::endl; }) { - boost::contract::guard c = boost::contract::constructor(this) + boost::contract::check c = boost::contract::constructor(this) .old([] { out << "a::ctor::old" << std::endl; }) .postcondition([] { out << "a::ctor::post" << std::endl; }) ; @@ -105,7 +105,7 @@ struct a } virtual ~a() { - boost::contract::guard c = boost::contract::destructor(this) + boost::contract::check c = boost::contract::destructor(this) .old([] { out << "a::dtor::old" << std::endl; }) .postcondition([] { out << "a::dtor::post" << std::endl; }) ; @@ -114,7 +114,7 @@ struct a virtual void f(char x, boost::contract::virtual_* v = 0) volatile /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_f>( v, static_cast( v, static_cast(&a::f), @@ -149,7 +149,7 @@ struct a } static void s() { - boost::contract::guard c = boost::contract::public_function() + boost::contract::check c = boost::contract::public_function() .precondition([] { out << "a::s::pre" << std::endl; }) .old([] { out << "a::s::old" << std::endl; }) .postcondition([] { out << "a::s::post" << std::endl; }) @@ -159,7 +159,7 @@ struct a protected: void p() volatile { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "a::p::volatile_pre" << std::endl; }) .old([] { out << "a::p::volatile_old" << std::endl; }) .postcondition([] { out << "a::p::volatile_post" << std::endl; }) @@ -168,7 +168,7 @@ protected: } void p() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "a::p::pre" << std::endl; }) .old([] { out << "a::p::old" << std::endl; }) .postcondition([] { out << "a::p::post" << std::endl; }) @@ -181,7 +181,7 @@ public: private: void q() volatile { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "a::q::volatile_pre" << std::endl; }) .old([] { out << "a::q::volatile_old" << std::endl; }) .postcondition([] { out << "a::q::volatile_post" << std::endl; }) @@ -190,7 +190,7 @@ private: } void q() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "a::q::pre" << std::endl; }) .old([] { out << "a::q::old" << std::endl; }) .postcondition([] { out << "a::q::post" << std::endl; }) diff --git a/test/invariant/mutable.hpp b/test/invariant/mutable.hpp index 70bbb36..582367d 100644 --- a/test/invariant/mutable.hpp +++ b/test/invariant/mutable.hpp @@ -9,14 +9,14 @@ // Test error if non-static inv declared mutable (unless PERMISSIVE #defined). #include -#include +#include struct a { void invariant() {} void f() { // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } }; diff --git a/test/invariant/static.hpp b/test/invariant/static.hpp index 05c8a11..c895f40 100644 --- a/test/invariant/static.hpp +++ b/test/invariant/static.hpp @@ -9,14 +9,14 @@ // Test error if non-static inv declared static (unless PERMISSIVE #defined). #include -#include +#include struct a { static void invariant() {} void f() { // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } }; diff --git a/test/invariant/static_const.hpp b/test/invariant/static_const.hpp index 87dc56b..274f1e4 100644 --- a/test/invariant/static_const.hpp +++ b/test/invariant/static_const.hpp @@ -9,14 +9,14 @@ // Test error if static inv declared const (unless PERMISSIVE #defined). #include -#include +#include struct a { void static_invariant() const {} void f() { // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } }; diff --git a/test/invariant/static_cv.hpp b/test/invariant/static_cv.hpp index cbdc974..b8353ab 100644 --- a/test/invariant/static_cv.hpp +++ b/test/invariant/static_cv.hpp @@ -9,14 +9,14 @@ // Test error if static inv declared cv (unless PERMISSIVE #defined). #include -#include +#include struct a { void static_invariant() const volatile {} void f() { // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } }; diff --git a/test/invariant/static_mutable.hpp b/test/invariant/static_mutable.hpp index bf3f815..baf7dba 100644 --- a/test/invariant/static_mutable.hpp +++ b/test/invariant/static_mutable.hpp @@ -9,14 +9,14 @@ // Test error if static inv declared mutable (unless PERMISSIVE #defined). #include -#include +#include struct a { void static_invariant() {} void f() { // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } }; diff --git a/test/invariant/static_volatile.hpp b/test/invariant/static_volatile.hpp index 6714c82..e23f4d8 100644 --- a/test/invariant/static_volatile.hpp +++ b/test/invariant/static_volatile.hpp @@ -9,14 +9,14 @@ // Test error if static inv declared volatile (unless PERMISSIVE #defined). #include -#include +#include struct a { void static_invariant() volatile {} void f() { // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } }; diff --git a/test/invariant/volatile.hpp b/test/invariant/volatile.hpp index 623480e..ef727f9 100644 --- a/test/invariant/volatile.hpp +++ b/test/invariant/volatile.hpp @@ -9,14 +9,14 @@ // Test error if non-static inv declared volatile (unless PERMISSIVE #defined). #include -#include +#include struct a { void invariant() volatile {} void f() { // Same for ctor and dtor (because they all use check_pre_post_inv). - boost::contract::guard c = boost::contract::public_function(this); + boost::contract::check c = boost::contract::public_function(this); } }; diff --git a/test/old/auto.cpp b/test/old/auto.cpp index bc9dbb3..c19d544 100644 --- a/test/old/auto.cpp +++ b/test/old/auto.cpp @@ -4,7 +4,7 @@ // 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 -// Test that OLDOF macro allows to use C++11 auto declarations. +// Test that OLD macro allows to use C++11 auto declarations. #include #ifndef BOOST_NO_CXX11_AUTO_DECLARATIONS @@ -16,13 +16,13 @@ int main() { #ifndef BOOST_NO_CXX11_AUTO_DECLARATIONS int x = 0; - auto old_x = BOOST_CONTRACT_OLDOF(x); + auto old_x = BOOST_CONTRACT_OLD(x); BOOST_STATIC_ASSERT(boost::is_same >::value); boost::contract::virtual_* v = 0; char y = 'a'; - auto old_y = BOOST_CONTRACT_OLDOF(v, y); + auto old_y = BOOST_CONTRACT_OLD(v, y); BOOST_STATIC_ASSERT(boost::is_same >::value); #endif // Else, nothing to test. diff --git a/test/old/noncopyable.cpp b/test/old/if_copyable.cpp similarity index 87% rename from test/old/noncopyable.cpp rename to test/old/if_copyable.cpp index 9cb7fa5..a016079 100644 --- a/test/old/noncopyable.cpp +++ b/test/old/if_copyable.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -21,9 +21,9 @@ unsigned old_checks; template struct b { virtual void next(T& x, boost::contract::virtual_* v = 0) { - boost::contract::old_ptr_noncopyable old_x = - BOOST_CONTRACT_OLDOF(v, x); - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::old_ptr_if_copyable old_x = + BOOST_CONTRACT_OLD(v, x); + boost::contract::check c = boost::contract::public_function(v, this) .postcondition([&] { if(old_x) { BOOST_CONTRACT_ASSERT(x > *old_x); @@ -45,9 +45,9 @@ struct a #undef BASES virtual void next(T& x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::old_ptr_noncopyable old_x = - BOOST_CONTRACT_OLDOF(v, x); - boost::contract::guard c = boost::contract::public_function< + boost::contract::old_ptr_if_copyable old_x = + BOOST_CONTRACT_OLD(v, x); + boost::contract::check c = boost::contract::public_function< override_next>(v, &a::next, this, x) .postcondition([&] { if(old_x) { @@ -63,8 +63,8 @@ struct a template void next(T& x) { - boost::contract::old_ptr_noncopyable old_x = BOOST_CONTRACT_OLDOF(x); - boost::contract::guard c = boost::contract::function() + boost::contract::old_ptr_if_copyable old_x = BOOST_CONTRACT_OLD(x); + boost::contract::check c = boost::contract::function() .postcondition([&] { if(old_x) { BOOST_CONTRACT_ASSERT(x > *old_x); diff --git a/test/old/noncopyable_error.cpp b/test/old/if_copyable_error.cpp similarity index 90% rename from test/old/noncopyable_error.cpp rename to test/old/if_copyable_error.cpp index a744387..48a7959 100644 --- a/test/old/noncopyable_error.cpp +++ b/test/old/if_copyable_error.cpp @@ -8,14 +8,14 @@ #include #include -#include +#include #include #include template void next(T& x) { - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); - boost::contract::guard c = boost::contract::function() + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(x); + boost::contract::check c = boost::contract::function() .postcondition([&] { BOOST_CONTRACT_ASSERT(x > *old_x); // No need to check if(old_x)... }) diff --git a/test/old/no_equal.cpp b/test/old/no_equal.cpp index 538fb75..9e3aee5 100644 --- a/test/old/no_equal.cpp +++ b/test/old/no_equal.cpp @@ -7,7 +7,7 @@ // Test assertions skipped when operations to check them missing (e.g., `==`). #include -#include +#include #include #include #include @@ -19,18 +19,18 @@ unsigned equal_skips; template -void push_back(std::vector& vect, T const& val) { - boost::contract::guard c = boost::contract::function() +void push_back(std::vector& vect, T const& value) { + boost::contract::check c = boost::contract::function() .postcondition([&] { BOOST_CONTRACT_ASSERT( boost::contract::call_if >( boost::bind(std::equal_to(), boost::cref(vect.back()), - boost::cref(val)) + boost::cref(value)) ).else_([] { ++equal_skips; return true; }) ); }) ; - vect.push_back(val); + vect.push_back(value); } struct j { // Type without operator==. diff --git a/test/old/no_equal_error.cpp b/test/old/no_equal_error.cpp index 40dacd8..0573c70 100644 --- a/test/old/no_equal_error.cpp +++ b/test/old/no_equal_error.cpp @@ -7,18 +7,18 @@ // Test assertion error when operations to check them missing (e.g., `==`). #include -#include +#include #include #include template -void push_back(std::vector& vect, T const& val) { - boost::contract::guard c = boost::contract::function() +void push_back(std::vector& vect, T const& value) { + boost::contract::check c = boost::contract::function() .postcondition([&] { - BOOST_CONTRACT_ASSERT(vect.back() == val); // Error (j has no ==). + BOOST_CONTRACT_ASSERT(vect.back() == value); // Error (j has no ==). }) ; - vect.push_back(val); + vect.push_back(value); } struct j { // Type without operator==. diff --git a/test/old/no_macros.hpp b/test/old/no_macros.hpp index fd81b9a..63a8807 100644 --- a/test/old/no_macros.hpp +++ b/test/old/no_macros.hpp @@ -4,7 +4,7 @@ // 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 -// Test old values without BOOST_CONTRACT_OLDOF macro. +// Test old values without BOOST_CONTRACT_OLD macro. #ifndef BOOST_CONTRACT_TEST_OLD_PTR_TYPE #error "must define BOOST_CONTRACT_TEST_OLD_PTR_TYPE" @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -39,7 +39,7 @@ void b::swap(i_type& i, j_type& j, boost::contract::virtual_* v) { boost::contract::null_old() ); BOOST_CONTRACT_TEST_OLD_PTR_TYPE old_j; - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { out << "b::swap::pre" << std::endl; BOOST_CONTRACT_ASSERT(i.value != j.value); @@ -67,7 +67,7 @@ struct a void swap(i_type& i, j_type& j, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_swap>(v, &a::swap, this, i, j); out << "a::swap::body" << std::endl; @@ -92,7 +92,7 @@ void swap(x_type& x, y_type& y) { boost::contract::null_old() ); BOOST_CONTRACT_TEST_OLD_PTR_TYPE old_y; - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([&] { out << "swap::pre" << std::endl; BOOST_CONTRACT_ASSERT(x.value != y.value); diff --git a/test/old/no_macros_noncopyable.cpp b/test/old/no_macros_if_copyable.cpp similarity index 96% rename from test/old/no_macros_noncopyable.cpp rename to test/old/no_macros_if_copyable.cpp index 261f7c3..26993e5 100644 --- a/test/old/no_macros_noncopyable.cpp +++ b/test/old/no_macros_if_copyable.cpp @@ -4,6 +4,6 @@ // 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 -#define BOOST_CONTRACT_TEST_OLD_PTR_TYPE boost::contract::old_ptr_noncopyable +#define BOOST_CONTRACT_TEST_OLD_PTR_TYPE boost::contract::old_ptr_if_copyable #include "no_macros.hpp" diff --git a/test/old/no_make_old_noncopyable_error.cpp b/test/old/no_make_old_if_copyable_error.cpp similarity index 96% rename from test/old/no_make_old_noncopyable_error.cpp rename to test/old/no_make_old_if_copyable_error.cpp index d467664..b8eb916 100644 --- a/test/old/no_make_old_noncopyable_error.cpp +++ b/test/old/no_make_old_if_copyable_error.cpp @@ -4,6 +4,6 @@ // 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 -#define BOOST_CONTRACT_TEST_OLD_PTR_TYPE boost::contract::old_ptr_noncopyable +#define BOOST_CONTRACT_TEST_OLD_PTR_TYPE boost::contract::old_ptr_if_copyable #include "no_make_old_error.hpp" diff --git a/test/public_function/access.cpp b/test/public_function/access.cpp index 42a092b..b6bfa6e 100644 --- a/test/public_function/access.cpp +++ b/test/public_function/access.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ class b { public: virtual void f(char ch, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { out << "b::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch == 'b'); @@ -56,7 +56,7 @@ class a public: virtual void f(char ch, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::f, this, ch) .precondition([&] { out << "a::f::pre" << std::endl; diff --git a/test/public_function/body_throw.cpp b/test/public_function/body_throw.cpp index 070faca..9637485 100644 --- a/test/public_function/body_throw.cpp +++ b/test/public_function/body_throw.cpp @@ -4,14 +4,14 @@ // 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 -// Test from public function (derived) body. +// Test throw from public function (derived) body. #include "../detail/oteststream.hpp" #include #include #include #include -#include +#include #include #include @@ -24,13 +24,14 @@ struct c { struct err {}; virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { + boost::contract::check c = boost::contract::public_function(v, this) + .precondition([] { out << "c::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(false); // To check derived pre. }) - .old([&] { out << "c::f::old" << std::endl; }) - .postcondition([&] { out << "c::f::post" << std::endl; }) + .old([] { out << "c::f::old" << std::endl; }) + .postcondition([] { out << "c::f::post" << std::endl; }) + .except([] { out << "c::f::except" << std::endl; }) ; out << "c::f::body" << std::endl; throw c::err(); // Test body throws. @@ -50,14 +51,15 @@ struct b struct err {}; virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &b::f, this) - .precondition([&] { + .precondition([] { out << "b::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(false); // To check derived pre. }) - .old([&] { out << "b::f::old" << std::endl; }) - .postcondition([&] { out << "b::f::post" << std::endl; }) + .old([] { out << "b::f::old" << std::endl; }) + .postcondition([] { out << "b::f::post" << std::endl; }) + .except([] { out << "b::f::except" << std::endl; }) ; out << "b::f::body" << std::endl; throw b::err(); // Test body throws. @@ -78,11 +80,12 @@ struct a struct err {}; void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::f, this) - .precondition([&] { out << "a::f::pre" << std::endl; }) - .old([&] { out << "a::f::old" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) + .precondition([] { out << "a::f::pre" << std::endl; }) + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) + .except([] { out << "a::f::except" << std::endl; }) ; out << "a::f::body" << std::endl; throw a::err(); // Test body throws. @@ -121,7 +124,7 @@ int main() { #endif << "a::f::body" << std::endl // Test this threw. #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS - // Test no post (but still subcontracted inv) as body threw. + // Test no post (but still subcon inv and except) as body threw. << "c::static_inv" << std::endl << "c::inv" << std::endl << "b::static_inv" << std::endl @@ -129,6 +132,11 @@ int main() { << "a::static_inv" << std::endl << "a::inv" << std::endl #endif + #ifndef BOOST_CONTRACT_NO_EXCEPTS + << "c::f::except" << std::endl + << "b::f::except" << std::endl + << "a::f::except" << std::endl + #endif ; BOOST_TEST(out.eq(ok.str())); } catch(...) { BOOST_TEST(false); } diff --git a/test/public_function/contracts.hpp b/test/public_function/contracts.hpp index 5c8ea4b..6ac3503 100644 --- a/test/public_function/contracts.hpp +++ b/test/public_function/contracts.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -58,16 +58,16 @@ result_type& t::f(s_type& s, boost::contract::virtual_* v) { std::ostringstream r; r << "none-" << Id; static result_type result(r.str()); boost::contract::old_ptr old_z = - BOOST_CONTRACT_OLDOF(v, z_type::eval(z)); + BOOST_CONTRACT_OLD(v, z_type::eval(z)); boost::contract::old_ptr old_s; - boost::contract::guard c = boost::contract::public_function(v, result, this) + boost::contract::check c = boost::contract::public_function(v, result, this) .precondition([&] { out << Id << "::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(s.value[0] == Id); }) .old([&] { out << Id << "::f::old" << std::endl; - old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); + old_s = BOOST_CONTRACT_OLD(v, s_type::eval(s)); }) .postcondition([&] (result_type const& result) { out << Id << "::f::post" << std::endl; @@ -107,9 +107,9 @@ struct c /* override */ { static result_type result("none-c"); boost::contract::old_ptr old_y = - BOOST_CONTRACT_OLDOF(v, y_type::eval(y)); + BOOST_CONTRACT_OLD(v, y_type::eval(y)); boost::contract::old_ptr old_s; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_f>(v, result, &c::f, this, s) .precondition([&] { out << "c::f::pre" << std::endl; @@ -117,7 +117,7 @@ struct c }) .old([&] { out << "c::f::old" << std::endl; - old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); + old_s = BOOST_CONTRACT_OLD(v, s_type::eval(s)); }) .postcondition([&] (result_type const& result) { out << "c::f::post" << std::endl; @@ -191,9 +191,9 @@ struct a /* override */ { static result_type result("none-a"); boost::contract::old_ptr old_x = - BOOST_CONTRACT_OLDOF(v, x_type::eval(x)); + BOOST_CONTRACT_OLD(v, x_type::eval(x)); boost::contract::old_ptr old_s; - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_f>(v, result, &a::f, this, s) .precondition([&] { out << "a::f::pre" << std::endl; @@ -201,7 +201,7 @@ struct a }) .old([&] { out << "a::f::old" << std::endl; - old_s = BOOST_CONTRACT_OLDOF(v, s_type::eval(s)); + old_s = BOOST_CONTRACT_OLD(v, s_type::eval(s)); }) .postcondition([&] (result_type const& result) { out << "a::f::post" << std::endl; diff --git a/test/public_function/decl.hpp b/test/public_function/decl.hpp index 0f5511a..14bf532 100644 --- a/test/public_function/decl.hpp +++ b/test/public_function/decl.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include boost::contract::test::detail::oteststream out; @@ -41,9 +41,9 @@ struct c { #endif virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) #ifndef BOOST_CONTRACT_TEST_NO_C_PRE - .precondition([&] { + .precondition([] { out << "c::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(c_pre); }) @@ -89,9 +89,9 @@ struct b #endif virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) #ifndef BOOST_CONTRACT_TEST_NO_B_PRE - .precondition([&] { + .precondition([] { out << "b::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(b_pre); }) @@ -137,10 +137,10 @@ struct a #endif virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::f, this) #ifndef BOOST_CONTRACT_TEST_NO_A_PRE - .precondition([&] { + .precondition([] { out << "a::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(a_pre); }) diff --git a/example/features/friend.cpp b/test/public_function/friend.cpp similarity index 83% rename from example/features/friend.cpp rename to test/public_function/friend.cpp index 97fd531..b25b5ce 100644 --- a/example/features/friend.cpp +++ b/test/public_function/friend.cpp @@ -37,16 +37,16 @@ private: }; void set_all(x& a, y& b, int value) { - boost::contract::guard post = boost::contract::function() + boost::contract::check post = boost::contract::function() .postcondition([&] { std::cout << "f::post" << std::endl; BOOST_CONTRACT_ASSERT(a.get() == value); BOOST_CONTRACT_ASSERT(b.get() == value); }) ; - boost::contract::guard inv_b = boost::contract::public_function(&b); - boost::contract::guard inv_a = boost::contract::public_function(&a); - boost::contract::guard pre = boost::contract::function() + boost::contract::check inv_b = boost::contract::public_function(&b); + boost::contract::check inv_a = boost::contract::public_function(&a); + boost::contract::check pre = boost::contract::function() .precondition([&] { std::cout << "f::pre" << std::endl; BOOST_CONTRACT_ASSERT(value > 0); diff --git a/test/public_function/ifdef_contracts.cpp b/test/public_function/ifdef_contracts.cpp index 0cf6c7b..7dbc4c1 100644 --- a/test/public_function/ifdef_contracts.cpp +++ b/test/public_function/ifdef_contracts.cpp @@ -13,7 +13,7 @@ #include #include #include - #include + #include #include #endif #include @@ -32,10 +32,10 @@ struct b { void b::f(int x, boost::contract::virtual_* v) { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(v, x); + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(v, x); #endif #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) #ifndef BOOST_CONTRACT_NO_PRECONDITIONS .precondition([] { out << "b::f::pre" << std::endl; }) #endif @@ -64,10 +64,10 @@ struct a virtual void f(int x, boost::contract::virtual_* v = 0) { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(v, x); + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(v, x); #endif #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_f>(v, &a::f, this, x) #ifndef BOOST_CONTRACT_NO_PRECONDITIONS .precondition([] { out << "a::f::pre" << std::endl; }) diff --git a/test/public_function/max_args.hpp b/test/public_function/max_args.hpp index 4b47859..a9853a7 100644 --- a/test/public_function/max_args.hpp +++ b/test/public_function/max_args.hpp @@ -8,7 +8,7 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include #include @@ -41,7 +41,7 @@ struct b { boost::contract::virtual_* v = 0 \ ) { \ int result = 0; \ - boost::contract::guard c = boost::contract::public_function( \ + boost::contract::check c = boost::contract::public_function( \ v, result, this) \ .precondition([] { \ out << "b::" << BOOST_PP_STRINGIZE(BOOST_PP_CAT(f, n)) << \ @@ -82,7 +82,7 @@ struct a boost::contract::virtual_* v = 0 \ ) /* override */ { \ int result = 0; \ - boost::contract::guard c = boost::contract::public_function< \ + boost::contract::check c = boost::contract::public_function< \ BOOST_PP_CAT(override_, BOOST_PP_CAT(f, n)) \ >( \ v, result, &a::BOOST_PP_CAT(f, n), this \ diff --git a/test/public_function/max_bases.cpp b/test/public_function/max_bases.cpp index 6c88b5a..9052eeb 100644 --- a/test/public_function/max_bases.cpp +++ b/test/public_function/max_bases.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include @@ -22,7 +22,7 @@ #define BOOST_CONTRACT_TEST_base_decl(z, n, unused) \ struct BOOST_PP_CAT(b, n) { \ virtual void f(boost::contract::virtual_* v = 0) { \ - boost::contract::guard c = boost::contract::public_function( \ + boost::contract::check c = boost::contract::public_function( \ v, this); \ } \ }; @@ -42,7 +42,7 @@ struct a #undef BASES void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::f, this); } BOOST_CONTRACT_OVERRIDE(f) diff --git a/test/public_function/old_throw.cpp b/test/public_function/old_throw.cpp index 26fffb1..67e1c77 100644 --- a/test/public_function/old_throw.cpp +++ b/test/public_function/old_throw.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -24,7 +24,7 @@ struct c { struct err {}; virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([] { out << "c::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(false); // To check derived pre. @@ -52,7 +52,7 @@ struct b struct err {}; virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &b::f, this) .precondition([] { out << "b::f::pre" << std::endl; @@ -82,7 +82,7 @@ struct a struct err {}; void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::f, this) .precondition([] { out << "a::f::pre" << std::endl; }) .old([] { diff --git a/test/public_function/overload.hpp b/test/public_function/overload.hpp index b548f81..f70c3b7 100644 --- a/test/public_function/overload.hpp +++ b/test/public_function/overload.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -22,7 +22,7 @@ struct b { void invariant() const { out << "b::inv" << std::endl; } virtual void f(int x, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([] { out << "b::f(int)::pre" << std::endl; }) .old([] { out << "b::f(int)::old" << std::endl; }) .postcondition([] { out << "b::f(int)::post" << std::endl; }) @@ -31,7 +31,7 @@ struct b { } virtual void f(char const* x, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([] { out << "b::f(char const*)::pre" << std::endl; }) .old([] { out << "b::f(char const*)::old" << std::endl; }) .postcondition( @@ -41,7 +41,7 @@ struct b { } virtual void f(int x, int y, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([] { out << "b::f(int, int)::pre" << std::endl; }) .old([] { out << "b::f(int, int)::old" << std::endl; }) .postcondition([] { out << "b::f(int, int)::post" << std::endl; }) @@ -50,7 +50,7 @@ struct b { } virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([] { out << "b::f()::pre" << std::endl; }) .old([] { out << "b::f()::old" << std::endl; }) .postcondition([] { out << "b::f()::post" << std::endl; }) @@ -59,7 +59,7 @@ struct b { } void f(int x[2][3], boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([] { out << "b::f(int[2][3])::pre" << std::endl; }) .old([] { out << "b::f(int[2][3])::old" << std::endl; }) .postcondition([] { out << "b::f(int[2][3])::post" << std::endl; }) @@ -68,7 +68,7 @@ struct b { } void f(void (*x)(int), boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition( [] { out << "b::f(void (*)(int))::pre" << std::endl; }) .old( @@ -91,7 +91,7 @@ struct a void invariant() const { out << "a::inv" << std::endl; } void f(int x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, static_cast(&a::f), this, x @@ -105,7 +105,7 @@ struct a // Test overload via argument type. void f(char const* x, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, static_cast( &a::f), @@ -121,7 +121,7 @@ struct a // Test overload via argument count. void f(int x, int y, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, static_cast( &a::f), @@ -137,7 +137,7 @@ struct a // Test overload via template argument type. template void f(T x) { // Template cannot be virtual (or override) in C++. - boost::contract::guard c = boost::contract::public_function(this) + boost::contract::check c = boost::contract::public_function(this) .precondition([] { out << "a::f(T)::pre" << std::endl; }) .old([] { out << "a::f(T)::old" << std::endl; }) .postcondition([] { out << "a::f(T)::post" << std::endl; }) @@ -160,7 +160,7 @@ struct a f0_ptr f0 = static_cast(&a::f); // Test this and public_function call in func below both take same 3 // args but they are ambiguous because of presence override_f. - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, f0, this) .precondition([] { out << "a::f()::pre" << std::endl; }) .old([] { out << "a::f()::old" << std::endl; }) @@ -174,7 +174,7 @@ struct a f0_ptr f0 = static_cast(&a::f); // Test this and public_function call in func above both take same 3 // args but they are ambiguous because of lack of override_f. - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, f0, this) .precondition([] { out << "a::f(bool)::pre" << std::endl; }) .old([] { out << "a::f(bool)::old" << std::endl; }) @@ -187,7 +187,7 @@ struct a // Test overload with array parameter. void f(int x[2][3], boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, static_cast( &a::f), @@ -202,7 +202,7 @@ struct a // Test overload with function pointer parameter. void f(void (*x)(int), boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, static_cast( &a::f), diff --git a/test/public_function/override.hpp b/test/public_function/override.hpp index 8e86917..f40e227 100644 --- a/test/public_function/override.hpp +++ b/test/public_function/override.hpp @@ -11,11 +11,11 @@ #include #include #include -#include +#include struct b { virtual void g(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this); + boost::contract::check c = boost::contract::public_function(v, this); } }; @@ -27,7 +27,7 @@ struct a #undef BASES virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_f>(v, &a::f, this); } BOOST_CONTRACT_OVERRIDE(f) diff --git a/test/public_function/protected.cpp b/test/public_function/protected.cpp index b394381..6781048 100644 --- a/test/public_function/protected.cpp +++ b/test/public_function/protected.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -26,7 +26,7 @@ protected: // (otherwise C++ won't override because mismatching parameters), but // overridden protected does not use public_function. virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "b::f::pre" << std::endl; }) .old([] { out << "b::f::old" << std::endl; }) .postcondition([] { out << "b::f::post" << std::endl; }) @@ -46,7 +46,7 @@ struct a void f(boost::contract::virtual_* v = 0) /* not override */ { // C++ func a::f overrides b::f, but contracts don't (so no override_f). - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([] { out << "a::f::pre" << std::endl; }) .old([] { out << "a::f::old" << std::endl; }) .postcondition([] { out << "a::f::post" << std::endl; }) diff --git a/test/public_function/protected_error.cpp b/test/public_function/protected_error.cpp index c95774a..cfc9a46 100644 --- a/test/public_function/protected_error.cpp +++ b/test/public_function/protected_error.cpp @@ -9,12 +9,12 @@ #include #include #include -#include +#include struct b { protected: virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this); + boost::contract::check c = boost::contract::public_function(v, this); } friend class boost::contract::access; // Test this cannot prevent error. @@ -27,7 +27,7 @@ struct a #undef BASES void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::f, this); } diff --git a/test/public_function/static.cpp b/test/public_function/static.cpp index effc3e6..6697ec0 100644 --- a/test/public_function/static.cpp +++ b/test/public_function/static.cpp @@ -9,7 +9,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include @@ -20,7 +20,7 @@ struct b { void invariant() const { out << "b::inv" << std::endl; } static void f() { - boost::contract::guard c = boost::contract::public_function() + boost::contract::check c = boost::contract::public_function() .precondition([] { out << "b::f::pre" << std::endl; }) .old([] { out << "b::f::old" << std::endl; }) .postcondition([] { out << "b::f::post" << std::endl; }) @@ -40,7 +40,7 @@ struct a void invariant() const { out << "a::inv" << std::endl; } static void f() { - boost::contract::guard c = boost::contract::public_function() + boost::contract::check c = boost::contract::public_function() .precondition([] { out << "a::f::pre" << std::endl; }) .old([] { out << "a::f::old" << std::endl; }) .postcondition([] { out << "a::f::post" << std::endl; }) diff --git a/test/public_function/static_body_throw.cpp b/test/public_function/static_body_throw.cpp index 7aee991..e69a1f8 100644 --- a/test/public_function/static_body_throw.cpp +++ b/test/public_function/static_body_throw.cpp @@ -8,7 +8,7 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include @@ -21,7 +21,7 @@ struct a { struct err {}; static void f() { - boost::contract::guard c = boost::contract::public_function() + boost::contract::check c = boost::contract::public_function() .precondition([] { out << "a::f::pre" << std::endl; }) .old([] { out << "a::f::old" << std::endl; }) .postcondition([] { out << "a::f::post" << std::endl; }) diff --git a/test/public_function/static_no_contracts.cpp b/test/public_function/static_no_contracts.cpp index d1220ca..b270500 100644 --- a/test/public_function/static_no_contracts.cpp +++ b/test/public_function/static_no_contracts.cpp @@ -10,7 +10,7 @@ #include #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS #include - #include + #include #include #endif #include @@ -26,10 +26,10 @@ struct a { static void f(int x) { #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS - boost::contract::old_ptr old_x = BOOST_CONTRACT_OLDOF(x); + boost::contract::old_ptr old_x = BOOST_CONTRACT_OLD(x); #endif #ifndef BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS - boost::contract::guard c = boost::contract::public_function() + boost::contract::check c = boost::contract::public_function() #ifndef BOOST_CONTRACT_NO_PRECONDITIONS .precondition([] { out << "a::f::pre" << std::endl; }) #endif diff --git a/test/public_function/static_old_throw.cpp b/test/public_function/static_old_throw.cpp index 9a0124b..61724a1 100644 --- a/test/public_function/static_old_throw.cpp +++ b/test/public_function/static_old_throw.cpp @@ -8,7 +8,7 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include @@ -21,7 +21,7 @@ struct a { struct err {}; static void f() { - boost::contract::guard c = boost::contract::public_function() + boost::contract::check c = boost::contract::public_function() .precondition([] { out << "a::f::pre" << std::endl; }) .old([] { out << "a::f::old" << std::endl; diff --git a/test/public_function/virtual_access.cpp b/test/public_function/virtual_access.cpp index 9290b2c..cea1b2b 100644 --- a/test/public_function/virtual_access.cpp +++ b/test/public_function/virtual_access.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -28,10 +28,10 @@ struct b { // Test all access levels (public, protected, and private). void invariant() const { out << "b::inv" << std::endl; } virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "b::f::pre" << std::endl; }) - .old([&] { out << "b::f::old" << std::endl; }) - .postcondition([&] { out << "b::f::post" << std::endl; }) + boost::contract::check c = boost::contract::public_function(v, this) + .precondition([] { out << "b::f::pre" << std::endl; }) + .old([] { out << "b::f::old" << std::endl; }) + .postcondition([] { out << "b::f::post" << std::endl; }) ; out << "b::f::body" << std::endl; } @@ -43,20 +43,20 @@ struct b { // Test all access levels (public, protected, and private). protected: virtual void g(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::function() - .precondition([&] { out << "b::g::pre" << std::endl; }) - .old([&] { out << "b::g::old" << std::endl; }) - .postcondition([&] { out << "b::g::post" << std::endl; }) + boost::contract::check c = boost::contract::function() + .precondition([] { out << "b::g::pre" << std::endl; }) + .old([] { out << "b::g::old" << std::endl; }) + .postcondition([] { out << "b::g::post" << std::endl; }) ; out << "b::g::body" << std::endl; } private: virtual void h(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::function() - .precondition([&] { out << "b::h::pre" << std::endl; }) - .old([&] { out << "b::h::old" << std::endl; }) - .postcondition([&] { out << "b::h::post" << std::endl; }) + boost::contract::check c = boost::contract::function() + .precondition([] { out << "b::h::pre" << std::endl; }) + .old([] { out << "b::h::old" << std::endl; }) + .postcondition([] { out << "b::h::post" << std::endl; }) ; out << "b::h::body" << std::endl; } @@ -73,11 +73,11 @@ struct a // Test overrides with mixed access levels from base. void invariant() const { out << "a::inv" << std::endl; } virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::f, this) - .precondition([&] { out << "a::f::pre" << std::endl; }) - .old([&] { out << "a::f::old" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) + .precondition([] { out << "a::f::pre" << std::endl; }) + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) ; out << "a::f::body" << std::endl; } @@ -87,19 +87,19 @@ struct a // Test overrides with mixed access levels from base. // they do not actually subcontract. virtual void g(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "a::g::pre" << std::endl; }) - .old([&] { out << "a::g::old" << std::endl; }) - .postcondition([&] { out << "a::g::post" << std::endl; }) + boost::contract::check c = boost::contract::public_function(v, this) + .precondition([] { out << "a::g::pre" << std::endl; }) + .old([] { out << "a::g::old" << std::endl; }) + .postcondition([] { out << "a::g::post" << std::endl; }) ; out << "a::g::body" << std::endl; } virtual void h(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "a::h::pre" << std::endl; }) - .old([&] { out << "a::h::old" << std::endl; }) - .postcondition([&] { out << "a::h::post" << std::endl; }) + boost::contract::check c = boost::contract::public_function(v, this) + .precondition([] { out << "a::h::pre" << std::endl; }) + .old([] { out << "a::h::old" << std::endl; }) + .postcondition([] { out << "a::h::post" << std::endl; }) ; out << "a::h::body" << std::endl; } diff --git a/test/public_function/virtual_access_multi.cpp b/test/public_function/virtual_access_multi.cpp index 9a25276..fa2842a 100644 --- a/test/public_function/virtual_access_multi.cpp +++ b/test/public_function/virtual_access_multi.cpp @@ -25,7 +25,7 @@ int main() { return 0; } // Test trivially passes on MSVC. #include #include #include -#include +#include #include #include @@ -36,28 +36,28 @@ struct c { // Test public access different from base `b`'s access below. void invariant() const { out << "c::inv" << std::endl; } virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "c::f::pre" << std::endl; }) - .old([&] { out << "c::f::old" << std::endl; }) - .postcondition([&] { out << "c::f::post" << std::endl; }) + boost::contract::check c = boost::contract::public_function(v, this) + .precondition([] { out << "c::f::pre" << std::endl; }) + .old([] { out << "c::f::old" << std::endl; }) + .postcondition([] { out << "c::f::post" << std::endl; }) ; out << "c::f::body" << std::endl; } virtual void g(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "c::g::pre" << std::endl; }) - .old([&] { out << "c::g::old" << std::endl; }) - .postcondition([&] { out << "c::g::post" << std::endl; }) + boost::contract::check c = boost::contract::public_function(v, this) + .precondition([] { out << "c::g::pre" << std::endl; }) + .old([] { out << "c::g::old" << std::endl; }) + .postcondition([] { out << "c::g::post" << std::endl; }) ; out << "c::g::body" << std::endl; } virtual void h(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "c::h::pre" << std::endl; }) - .old([&] { out << "c::h::old" << std::endl; }) - .postcondition([&] { out << "c::h::post" << std::endl; }) + boost::contract::check c = boost::contract::public_function(v, this) + .precondition([] { out << "c::h::pre" << std::endl; }) + .old([] { out << "c::h::old" << std::endl; }) + .postcondition([] { out << "c::h::post" << std::endl; }) ; out << "c::h::body" << std::endl; } @@ -74,10 +74,10 @@ struct b { // Test all access levels (public, protected, and private). void invariant() const { out << "b::inv" << std::endl; } virtual void f(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) - .precondition([&] { out << "b::f::pre" << std::endl; }) - .old([&] { out << "b::f::old" << std::endl; }) - .postcondition([&] { out << "b::f::post" << std::endl; }) + boost::contract::check c = boost::contract::public_function(v, this) + .precondition([] { out << "b::f::pre" << std::endl; }) + .old([] { out << "b::f::old" << std::endl; }) + .postcondition([] { out << "b::f::post" << std::endl; }) ; out << "b::f::body" << std::endl; } @@ -89,20 +89,20 @@ struct b { // Test all access levels (public, protected, and private). protected: virtual void g(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::function() - .precondition([&] { out << "b::g::pre" << std::endl; }) - .old([&] { out << "b::g::old" << std::endl; }) - .postcondition([&] { out << "b::g::post" << std::endl; }) + boost::contract::check c = boost::contract::function() + .precondition([] { out << "b::g::pre" << std::endl; }) + .old([] { out << "b::g::old" << std::endl; }) + .postcondition([] { out << "b::g::post" << std::endl; }) ; out << "b::g::body" << std::endl; } private: virtual void h(boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::function() - .precondition([&] { out << "b::h::pre" << std::endl; }) - .old([&] { out << "b::h::old" << std::endl; }) - .postcondition([&] { out << "b::h::post" << std::endl; }) + boost::contract::check c = boost::contract::function() + .precondition([] { out << "b::h::pre" << std::endl; }) + .old([] { out << "b::h::old" << std::endl; }) + .postcondition([] { out << "b::h::post" << std::endl; }) ; out << "b::h::body" << std::endl; } @@ -119,31 +119,31 @@ struct a // Test overrides with mixed access levels from different bases. void invariant() const { out << "a::inv" << std::endl; } virtual void f(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::f, this) - .precondition([&] { out << "a::f::pre" << std::endl; }) - .old([&] { out << "a::f::old" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) + .precondition([] { out << "a::f::pre" << std::endl; }) + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) ; out << "a::f::body" << std::endl; } virtual void g(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::g, this) - .precondition([&] { out << "a::g::pre" << std::endl; }) - .old([&] { out << "a::g::old" << std::endl; }) - .postcondition([&] { out << "a::g::post" << std::endl; }) + .precondition([] { out << "a::g::pre" << std::endl; }) + .old([] { out << "a::g::old" << std::endl; }) + .postcondition([] { out << "a::g::post" << std::endl; }) ; out << "a::g::body" << std::endl; } virtual void h(boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, &a::h, this) - .precondition([&] { out << "a::h::pre" << std::endl; }) - .old([&] { out << "a::h::old" << std::endl; }) - .postcondition([&] { out << "a::h::post" << std::endl; }) + .precondition([] { out << "a::h::pre" << std::endl; }) + .old([] { out << "a::h::old" << std::endl; }) + .postcondition([] { out << "a::h::post" << std::endl; }) ; out << "a::h::body" << std::endl; } diff --git a/test/public_function/virtual_sparse.cpp b/test/public_function/virtual_sparse.cpp index 878b737..ab14b33 100644 --- a/test/public_function/virtual_sparse.cpp +++ b/test/public_function/virtual_sparse.cpp @@ -9,7 +9,7 @@ #include "../detail/oteststream.hpp" #include #include -#include +#include #include #include #include @@ -22,13 +22,13 @@ struct j { void invariant() const { out << "j::inv" << std::endl; } virtual void f(char ch, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { out << "j::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch == 'j'); }) - .old([&] { out << "j::f::old" << std::endl; }) - .postcondition([&] { out << "j::f::post" << std::endl; }) + .old([] { out << "j::f::old" << std::endl; }) + .postcondition([] { out << "j::f::post" << std::endl; }) ; out << "j::f::body" << std::endl; } @@ -39,13 +39,13 @@ struct i { void invariant() const { out << "i::inv" << std::endl; } virtual void f(char ch, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { out << "i::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch == 'i'); }) - .old([&] { out << "i::f::old" << std::endl; }) - .postcondition([&] { out << "i::f::post" << std::endl; }) + .old([] { out << "i::f::old" << std::endl; }) + .postcondition([] { out << "i::f::post" << std::endl; }) ; out << "i::f::body" << std::endl; } @@ -64,14 +64,14 @@ struct h void invariant() const { out << "h::inv" << std::endl; } virtual void f(char ch, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_f>(v, &h::f, this, ch) .precondition([&] { out << "h::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch == 'h'); }) - .old([&] { out << "h::f::old" << std::endl; }) - .postcondition([&] { out << "h::f::post" << std::endl; }) + .old([] { out << "h::f::old" << std::endl; }) + .postcondition([] { out << "h::f::post" << std::endl; }) ; out << "h::f::body" << std::endl; } @@ -89,14 +89,14 @@ struct e void invariant() const { out << "e::inv" << std::endl; } virtual void f(char ch, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_f>(v, &e::f, this, ch) .precondition([&] { out << "e::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch == 'e'); }) - .old([&] { out << "e::f::old" << std::endl; }) - .postcondition([&] { out << "e::f::post" << std::endl; }) + .old([] { out << "e::f::old" << std::endl; }) + .postcondition([] { out << "e::f::post" << std::endl; }) ; out << "e::f::body" << std::endl; } @@ -119,13 +119,13 @@ struct c { void invariant() const { out << "c::inv" << std::endl; } virtual void f(char ch, boost::contract::virtual_* v = 0) { - boost::contract::guard c = boost::contract::public_function(v, this) + boost::contract::check c = boost::contract::public_function(v, this) .precondition([&] { out << "c::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch == 'c'); }) - .old([&] { out << "c::f::old" << std::endl; }) - .postcondition([&] { out << "c::f::post" << std::endl; }) + .old([] { out << "c::f::old" << std::endl; }) + .postcondition([] { out << "c::f::post" << std::endl; }) ; out << "c::f::body" << std::endl; } @@ -158,14 +158,14 @@ struct a void invariant() const { out << "a::inv" << std::endl; } virtual void f(char ch, boost::contract::virtual_* v = 0) /* override */ { - boost::contract::guard c = boost::contract::public_function< + boost::contract::check c = boost::contract::public_function< override_f>(v, &a::f, this, ch) .precondition([&] { out << "a::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch == 'a'); }) - .old([&] { out << "a::f::old" << std::endl; }) - .postcondition([&] { out << "a::f::post" << std::endl; }) + .old([] { out << "a::f::old" << std::endl; }) + .postcondition([] { out << "a::f::post" << std::endl; }) ; out << "a::f::body" << std::endl; } diff --git a/test/result/mixed_optional.hpp b/test/result/mixed_optional.hpp index 59718cf..9c8dca1 100644 --- a/test/result/mixed_optional.hpp +++ b/test/result/mixed_optional.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include @@ -46,13 +46,13 @@ struct d { ch_type& ch, boost::contract::virtual_* v = 0) { unsigned const old_ch_copies = ch_type::copies(); boost::optional result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, this) .precondition([&] { out << "d::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch.value == 'd'); }) - .old([&] { out << "d::f::old" << std::endl; }) + .old([] { out << "d::f::old" << std::endl; }) .postcondition([&] (boost::optional const& result) { out << "d::f::post" << std::endl; BOOST_CONTRACT_ASSERT(result->value == ch.value); @@ -81,13 +81,13 @@ struct c ch_type& ch, boost::contract::virtual_* v = 0) /* override */ { unsigned const old_ch_copies = ch_type::copies(); boost::optional result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, &c::f, this, ch) .precondition([&] { out << "c::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch.value == 'c'); }) - .old([&] { out << "c::f::old" << std::endl; }) + .old([] { out << "c::f::old" << std::endl; }) .postcondition([&] (boost::optional const& result) { out << "c::f::post" << std::endl; BOOST_CONTRACT_ASSERT(result->value == ch.value); @@ -117,13 +117,13 @@ struct b ch_type& ch, boost::contract::virtual_* v = 0) /* override */ { unsigned const old_ch_copies = ch_type::copies(); BOOST_CONTRACT_TEST_CH_TYPE result BOOST_CONTRACT_TEST_CH_INIT; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, &b::f, this, ch) .precondition([&] { out << "b::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch.value == 'b'); }) - .old([&] { out << "b::f::old" << std::endl; }) + .old([] { out << "b::f::old" << std::endl; }) .postcondition([&] (ch_type const& result) { out << "b::f::post" << std::endl; BOOST_CONTRACT_ASSERT(result.value == ch.value); @@ -153,13 +153,13 @@ struct a ch_type& ch, boost::contract::virtual_* v = 0) /* override */ { unsigned const old_ch_copies = ch_type::copies(); boost::optional result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, &a::f, this, ch) .precondition([&] { out << "a::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch.value == 'a'); }) - .old([&] { out << "a::f::old" << std::endl; }) + .old([] { out << "a::f::old" << std::endl; }) .postcondition([&] (boost::optional const& result) { out << "a::f::post" << std::endl; BOOST_CONTRACT_ASSERT(result->value == ch.value); @@ -189,13 +189,13 @@ struct e ch_type& ch, boost::contract::virtual_* v = 0) /* override */ { unsigned const old_ch_copies = ch_type::copies(); BOOST_CONTRACT_TEST_CH_TYPE result BOOST_CONTRACT_TEST_CH_INIT; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, &e::f, this, ch) .precondition([&] { out << "e::f::pre" << std::endl; BOOST_CONTRACT_ASSERT(ch.value == 'e'); }) - .old([&] { out << "e::f::old" << std::endl; }) + .old([] { out << "e::f::old" << std::endl; }) .postcondition([&] (ch_type const& result) { out << "e::f::post" << std::endl; BOOST_CONTRACT_ASSERT(result.value == ch.value); diff --git a/test/result/type_mismatch_error.cpp b/test/result/type_mismatch_error.cpp index 4f3d8ff..0ad2586 100644 --- a/test/result/type_mismatch_error.cpp +++ b/test/result/type_mismatch_error.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include struct b { virtual int f(boost::contract::virtual_* v = 0) { @@ -17,7 +17,7 @@ struct b { // in this case public_function does not that &b::f as param (but this // will error at run-time on a virtual call via a derived class). char result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, this); return result; } @@ -32,7 +32,7 @@ struct a virtual int f(boost::contract::virtual_* v = 0) /* override */ { char result; - boost::contract::guard c = boost::contract::public_function( + boost::contract::check c = boost::contract::public_function( v, result, &a::f, this); // Error (result time mismatch). return result; } diff --git a/test/specify/no_guard.cpp b/test/specify/missing_check_decl.cpp similarity index 78% rename from test/specify/no_guard.cpp rename to test/specify/missing_check_decl.cpp index abc2faf..4e46846 100644 --- a/test/specify/no_guard.cpp +++ b/test/specify/missing_check_decl.cpp @@ -4,24 +4,24 @@ // 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 -// Test missing contract guard gives run-time error. +// Test missing contract check declaration gives run-time error. struct err {}; -#define BOOST_CONTRACT_ON_MISSING_GUARD { throw err(); } +#define BOOST_CONTRACT_ON_MISSING_CHECK_DECL { throw err(); } #include -#include +#include #include int main() { - boost::contract::guard c = boost::contract::function() // Test this is OK. + boost::contract::check c = boost::contract::function() // Test this is OK. .precondition([] {}) .old([] {}) .postcondition([] {}) ; try { - boost::contract::function() // Test no `guard c = ...` errors. + boost::contract::function() // Test no `check c = ...` errors. .precondition([] {}) .old([] {}) .postcondition([] {}) diff --git a/test/specify/nothing.cpp b/test/specify/nothing.cpp index 9abd79a..74be46e 100644 --- a/test/specify/nothing.cpp +++ b/test/specify/nothing.cpp @@ -8,14 +8,14 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include boost::contract::test::detail::oteststream out; void f() { - boost::contract::guard c = boost::contract::function(); + boost::contract::check c = boost::contract::function(); out << "f::body" << std::endl; } diff --git a/test/specify/old.cpp b/test/specify/old.cpp index d851f1f..ac24259 100644 --- a/test/specify/old.cpp +++ b/test/specify/old.cpp @@ -8,14 +8,14 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include boost::contract::test::detail::oteststream out; void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .old([] { out << "f::old" << std::endl; }) ; out << "f::body" << std::endl; diff --git a/test/specify/old_post.cpp b/test/specify/old_post.cpp index c3fe687..bdc2e29 100644 --- a/test/specify/old_post.cpp +++ b/test/specify/old_post.cpp @@ -8,14 +8,14 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include boost::contract::test::detail::oteststream out; void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .old([] { out << "f::old" << std::endl; }) .postcondition([] { out << "f::post" << std::endl; }) ; diff --git a/test/specify/old_pre_error.cpp b/test/specify/old_pre_error.cpp index 82f0bf5..fdc2129 100644 --- a/test/specify/old_pre_error.cpp +++ b/test/specify/old_pre_error.cpp @@ -7,10 +7,10 @@ // Test old before pre error (for free func, but same for all contracts). #include -#include +#include void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .old([] {}) // Error (old before pre). .precondition([] {}) ; diff --git a/test/specify/post.cpp b/test/specify/post.cpp index 5e18144..8f55912 100644 --- a/test/specify/post.cpp +++ b/test/specify/post.cpp @@ -8,14 +8,14 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include boost::contract::test::detail::oteststream out; void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .postcondition([] { out << "f::post" << std::endl; }) ; out << "f::body" << std::endl; diff --git a/test/specify/post_old_error.cpp b/test/specify/post_old_error.cpp index 46f107a..aa333db 100644 --- a/test/specify/post_old_error.cpp +++ b/test/specify/post_old_error.cpp @@ -7,10 +7,10 @@ // Test post before old error (for free func, but same for all contracts). #include -#include +#include void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .postcondition([] {}) // Error (post before old). .old([] {}) ; diff --git a/test/specify/post_pre_error.cpp b/test/specify/post_pre_error.cpp index 235ac98..205299a 100644 --- a/test/specify/post_pre_error.cpp +++ b/test/specify/post_pre_error.cpp @@ -7,10 +7,10 @@ // Test post before pre error (for free func, but same for all contracts). #include -#include +#include void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .postcondition([] {}) // Error (post before pre). .precondition([] {}) ; diff --git a/test/specify/pre.cpp b/test/specify/pre.cpp index 9dfef27..32a6e5f 100644 --- a/test/specify/pre.cpp +++ b/test/specify/pre.cpp @@ -8,14 +8,14 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include boost::contract::test::detail::oteststream out; void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "f::pre" << std::endl; }) ; out << "f::body" << std::endl; diff --git a/test/specify/pre_old.cpp b/test/specify/pre_old.cpp index 4a667db..30f0c22 100644 --- a/test/specify/pre_old.cpp +++ b/test/specify/pre_old.cpp @@ -8,14 +8,14 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include boost::contract::test::detail::oteststream out; void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "f::pre" << std::endl; }) .old([] { out << "f::old" << std::endl; }) ; diff --git a/test/specify/pre_old_post.cpp b/test/specify/pre_old_post.cpp index 149bee1..e90ebe0 100644 --- a/test/specify/pre_old_post.cpp +++ b/test/specify/pre_old_post.cpp @@ -8,14 +8,14 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include boost::contract::test::detail::oteststream out; void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "f::pre" << std::endl; }) .old([] { out << "f::old" << std::endl; }) .postcondition([] { out << "f::post" << std::endl; }) diff --git a/test/specify/pre_post.cpp b/test/specify/pre_post.cpp index 0eb6e4d..a355499 100644 --- a/test/specify/pre_post.cpp +++ b/test/specify/pre_post.cpp @@ -8,14 +8,14 @@ #include "../detail/oteststream.hpp" #include -#include +#include #include #include boost::contract::test::detail::oteststream out; void f() { - boost::contract::guard c = boost::contract::function() + boost::contract::check c = boost::contract::function() .precondition([] { out << "f::pre" << std::endl; }) .postcondition([] { out << "f::post" << std::endl; }) ;