]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/contract/test/destructor/throwing_old.cpp
2 // Copyright (C) 2008-2018 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0 (see accompanying
4 // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
5 // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
7 // Test throw from destructor .old() (in middle branch of inheritance tree).
9 #include "../detail/oteststream.hpp"
10 #include <boost/contract/destructor.hpp>
11 #include <boost/contract/base_types.hpp>
12 #include <boost/contract/check.hpp>
13 #include <boost/config.hpp>
14 #include <boost/detail/lightweight_test.hpp>
17 boost::contract::test::detail::oteststream out
;
20 static void static_invariant() { out
<< "c::static_inv" << std::endl
; }
21 void invariant() const { out
<< "c::inv" << std::endl
; }
23 ~c() BOOST_NOEXCEPT_IF(false) {
24 boost::contract::check c
= boost::contract::destructor(this)
25 .old([] { out
<< "c::dtor::old" << std::endl
; })
26 .postcondition([] { out
<< "c::dtor::post" << std::endl
; })
27 .except([] { out
<< "c::dtor::except" << std::endl
; })
29 out
<< "c::dtor::body" << std::endl
;
30 // Do not throw (from inheritance root).
34 struct b_err
{}; // Global decl so visible in MSVC10 lambdas.
37 #define BASES public c
40 typedef BOOST_CONTRACT_BASE_TYPES(BASES
) base_types
;
43 static void static_invariant() { out
<< "b::static_inv" << std::endl
; }
44 void invariant() const { out
<< "b::inv" << std::endl
; }
46 ~b() BOOST_NOEXCEPT_IF(false) {
47 boost::contract::check c
= boost::contract::destructor(this)
49 out
<< "b::dtor::old" << std::endl
;
50 throw b_err(); // Test this throws (from mid branch).
52 .postcondition([] { out
<< "b::dtor::post" << std::endl
; })
53 .except([] { out
<< "b::dtor::except" << std::endl
; })
55 out
<< "b::dtor::body" << std::endl
;
60 #define BASES public b
63 typedef BOOST_CONTRACT_BASE_TYPES(BASES
) base_types
;
66 static void static_invariant() { out
<< "a::static_inv" << std::endl
; }
67 void invariant() const { out
<< "a::inv" << std::endl
; }
69 ~a() BOOST_NOEXCEPT_IF(false) {
70 boost::contract::check c
= boost::contract::destructor(this)
71 .old([] { out
<< "a::dtor::old" << std::endl
; })
72 .postcondition([] { out
<< "a::dtor::post" << std::endl
; })
73 .except([] { out
<< "a::dtor::except" << std::endl
; })
75 out
<< "a::dtor::body" << std::endl
;
76 // Do not throw (from inheritance leaf).
81 std::ostringstream ok
;
83 boost::contract::set_old_failure([] (boost::contract::from
) { throw; });
90 #ifndef BOOST_CONTRACT_NO_OLDS
92 } catch(b_err
const&) {
95 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
96 << "a::static_inv" << std::endl
97 << "a::inv" << std::endl
99 #ifndef BOOST_CONTRACT_NO_OLDS
100 << "a::dtor::old" << std::endl
102 << "a::dtor::body" << std::endl
103 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
104 // Test a destructed (so only static_inv and post, but no inv).
105 << "a::static_inv" << std::endl
107 #ifndef BOOST_CONTRACT_NO_POSTCONDITIONS
108 << "a::dtor::post" << std::endl
111 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
112 << "b::static_inv" << std::endl
113 << "b::inv" << std::endl
115 #ifndef BOOST_CONTRACT_NO_OLDS
116 << "b::dtor::old" << std::endl
// Test this threw.
118 << "b::dtor::body" << std::endl
119 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
120 << "b::static_inv" << std::endl
124 #ifndef BOOST_CONTRACT_NO_ENTRY_INVARIANTS
125 << "c::static_inv" << std::endl
126 << "c::inv" << std::endl
128 #ifndef BOOST_CONTRACT_NO_OLDS
129 << "c::dtor::old" << std::endl
131 << "c::dtor::body" << std::endl
132 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
133 << "c::static_inv" << std::endl
135 #ifndef BOOST_CONTRACT_NO_OLDS
136 // Test c not destructed (so both inv and except).
137 #ifndef BOOST_CONTRACT_NO_EXIT_INVARIANTS
138 << "c::inv" << std::endl
140 #ifndef BOOST_CONTRACT_NO_EXCEPTS
141 << "c::dtor::except" << std::endl
145 BOOST_TEST(out
.eq(ok
.str()));
146 } catch(...) { BOOST_TEST(false); }
148 return boost::report_errors();