2 #ifndef BOOST_CONTRACT_DETAIL_CONSTRUCTOR_HPP_
3 #define BOOST_CONTRACT_DETAIL_CONSTRUCTOR_HPP_
5 // Copyright (C) 2008-2018 Lorenzo Caminiti
6 // Distributed under the Boost Software License, Version 1.0 (see accompanying
7 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
8 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
10 #include <boost/contract/core/exception.hpp>
11 #include <boost/contract/core/config.hpp>
12 #include <boost/contract/detail/condition/cond_inv.hpp>
13 #include <boost/contract/detail/none.hpp>
14 #include <boost/contract/detail/exception.hpp>
15 #if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
16 !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
17 !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
18 !defined(BOOST_CONTRACT_NO_EXCEPTS))
19 #include <boost/contract/detail/checking.hpp>
21 #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
22 !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
23 !defined(BOOST_CONTRACT_NO_EXCEPTS)
24 #include <boost/config.hpp>
28 namespace boost { namespace contract { namespace detail {
30 // Ctor subcontracting impl via C++ obj construction mechanism.
31 template<class C> // Non-copyable base.
32 class constructor : public cond_inv</* VR = */ none, C> {
34 explicit constructor(C* obj) : cond_inv</* VR = */ none, C>(
35 boost::contract::from_constructor, obj) {}
38 #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
39 !defined(BOOST_CONTRACT_NO_OLDS)
40 void init() /* override */ {
41 #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
42 if(checking::already()) return;
45 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
47 #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
50 this->check_entry_static_inv();
51 // No object before ctor body so check only static inv at
52 // entry. Ctor pre checked by constructor_precondition.
55 #ifndef BOOST_CONTRACT_NO_OLDS
62 #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
63 !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
64 !defined(BOOST_CONTRACT_NO_EXCEPTS)
65 ~constructor() BOOST_NOEXCEPT_IF(false) {
66 this->assert_initialized();
67 #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
68 if(checking::already()) return;
72 // If ctor body threw, no obj so check only static inv. Otherwise,
73 // obj constructed so check static inv, non-static inv, and post.
74 if(uncaught_exception()) {
75 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
76 this->check_exit_static_inv();
78 #ifndef BOOST_CONTRACT_NO_EXCEPTS
82 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
83 this->check_exit_all_inv();
85 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
86 this->check_post(none());
95 #endif // #include guard