]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/contract/detail/operation/destructor.hpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / boost / contract / detail / operation / destructor.hpp
1
2 #ifndef BOOST_CONTRACT_DETAIL_DESTRUCTOR_HPP_
3 #define BOOST_CONTRACT_DETAIL_DESTRUCTOR_HPP_
4
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
9
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 #if !defined(BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION) && ( \
15 !defined(BOOST_CONTRACT_NO_INVARIANTS) || \
16 !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
17 !defined(BOOST_CONTRACT_NO_EXCEPTS))
18 #include <boost/contract/detail/checking.hpp>
19 #endif
20 #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
21 !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
22 !defined(BOOST_CONTRACT_NO_EXCEPTS)
23 #include <boost/config.hpp>
24 #include <exception>
25 #endif
26
27 namespace boost { namespace contract { namespace detail {
28
29 // Dtor subcontracting impl via C++ obj destruction mechanism.
30 template<class C> // Non-copyable base.
31 class destructor : public cond_inv</* VR = */ none, C> {
32 public:
33 explicit destructor(C* obj) : cond_inv</* VR = */ none, C>(
34 boost::contract::from_destructor, obj) {}
35
36 private:
37 #if !defined(BOOST_CONTRACT_NO_ENTRY_INVARIANTS) || \
38 !defined(BOOST_CONTRACT_NO_OLDS)
39 void init() /* override */ {
40 #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
41 if(checking::already()) return;
42 #endif
43
44 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
45 {
46 #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
47 checking k;
48 #endif
49 // Obj exists (before dtor body), check static and non- inv.
50 this->check_entry_all_inv();
51 // Dtor cannot have pre because it has no parameters.
52 }
53 #endif
54 #ifndef BOOST_CONTRACT_NO_OLDS
55 this->copy_old();
56 #endif
57 }
58 #endif
59
60 public:
61 #if !defined(BOOST_CONTRACT_NO_EXIT_INVARIANTS) || \
62 !defined(BOOST_CONTRACT_NO_POSTCONDITIONS) || \
63 !defined(BOOST_CONTRACT_NO_EXCEPTS)
64 ~destructor() BOOST_NOEXCEPT_IF(false) {
65 this->assert_initialized();
66 #ifndef BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION
67 if(checking::already()) return;
68 checking k;
69 #endif
70
71 // If dtor body threw, obj still exists so check subcontracted
72 // static and non- inv (but no post because of throw). Otherwise,
73 // obj destructed so check static inv and post (even if there is no
74 // obj after dtor body, this library allows dtor post, for example
75 // to check static members for an instance counter class).
76 // NOTE: In theory C++ destructors should not throw, but the
77 // language allows for that (even if in C++11 dtors declarations are
78 // implicitly noexcept(true) unless specified otherwise) so this
79 // library must handle such a case.
80 if(std::uncaught_exception()) {
81 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
82 this->check_exit_all_inv();
83 #endif
84 #ifndef BOOST_CONTRACT_NO_EXCEPTS
85 this->check_except();
86 #endif
87 } else {
88 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
89 this->check_exit_static_inv();
90 #endif
91 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
92 this->check_post(none());
93 #endif
94 }
95 }
96 #endif
97 };
98
99 } } } // namespace
100
101 #endif // #include guard
102