]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_throws_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / smart_ptr / test / allocate_shared_array_throws_test.cpp
CommitLineData
7c673cae 1/*
b32b8144
FG
2Copyright 2012-2015 Glen Joseph Fernandes
3(glenjofe@gmail.com)
7c673cae 4
b32b8144
FG
5Distributed under the Boost Software License, Version 1.0.
6(http://www.boost.org/LICENSE_1_0.txt)
7c673cae
FG
7*/
8#include <boost/core/lightweight_test.hpp>
9#include <boost/smart_ptr/make_shared.hpp>
10
b32b8144
FG
11template<class T = void>
12struct creator {
13 typedef T value_type;
14
15 template<class U>
16 struct rebind {
17 typedef creator<U> other;
18 };
19
20 creator() { }
21
22 template<class U>
23 creator(const creator<U>&) { }
24
25 T* allocate(std::size_t size) {
26 return static_cast<T*>(::operator new(sizeof(T) * size));
27 }
28
29 void deallocate(T* ptr, std::size_t) {
30 ::operator delete(ptr);
31 }
32};
33
34template<class T, class U>
35inline bool
36operator==(const creator<T>&, const creator<U>&)
37{
38 return true;
39}
40
41template<class T, class U>
42inline bool
43operator!=(const creator<T>&, const creator<U>&)
44{
45 return false;
46}
47
7c673cae
FG
48class type {
49public:
b32b8144
FG
50 static unsigned instances;
51
52 type() {
7c673cae
FG
53 if (instances == 5) {
54 throw true;
55 }
b32b8144 56 ++instances;
7c673cae 57 }
b32b8144 58
7c673cae 59 ~type() {
b32b8144 60 --instances;
7c673cae 61 }
b32b8144 62
7c673cae
FG
63private:
64 type(const type&);
65 type& operator=(const type&);
66};
67
b32b8144 68unsigned type::instances = 0;
7c673cae
FG
69
70int main()
71{
72 try {
b32b8144 73 boost::allocate_shared<type[]>(creator<type>(), 6);
7c673cae
FG
74 BOOST_ERROR("allocate_shared did not throw");
75 } catch (...) {
76 BOOST_TEST(type::instances == 0);
77 }
78 try {
b32b8144 79 boost::allocate_shared<type[][2]>(creator<type>(), 3);
7c673cae
FG
80 BOOST_ERROR("allocate_shared did not throw");
81 } catch (...) {
82 BOOST_TEST(type::instances == 0);
83 }
84 try {
b32b8144 85 boost::allocate_shared<type[6]>(creator<>());
7c673cae
FG
86 BOOST_ERROR("allocate_shared did not throw");
87 } catch (...) {
88 BOOST_TEST(type::instances == 0);
89 }
90 try {
b32b8144 91 boost::allocate_shared<type[3][2]>(creator<>());
7c673cae
FG
92 BOOST_ERROR("allocate_shared did not throw");
93 } catch (...) {
94 BOOST_TEST(type::instances == 0);
95 }
96 try {
b32b8144 97 boost::allocate_shared_noinit<type[]>(creator<>(), 6);
7c673cae
FG
98 BOOST_ERROR("allocate_shared_noinit did not throw");
99 } catch (...) {
100 BOOST_TEST(type::instances == 0);
101 }
102 try {
b32b8144 103 boost::allocate_shared_noinit<type[][2]>(creator<>(), 3);
7c673cae
FG
104 BOOST_ERROR("allocate_shared_noinit did not throw");
105 } catch (...) {
106 BOOST_TEST(type::instances == 0);
107 }
108 try {
b32b8144 109 boost::allocate_shared_noinit<type[6]>(creator<>());
7c673cae
FG
110 BOOST_ERROR("allocate_shared_noinit did not throw");
111 } catch (...) {
112 BOOST_TEST(type::instances == 0);
113 }
114 try {
b32b8144 115 boost::allocate_shared_noinit<type[3][2]>(creator<>());
7c673cae
FG
116 BOOST_ERROR("allocate_shared_noinit did not throw");
117 } catch (...) {
118 BOOST_TEST(type::instances == 0);
119 }
120 return boost::report_errors();
121}