1 | /* |
---|---|
2 | Copyright 2014 Glen Joseph Fernandes |
3 | (glenjofe@gmail.com) |
4 | |
5 | Distributed under the Boost Software License, Version 1.0. |
6 | (http://www.boost.org/LICENSE_1_0.txt) |
7 | */ |
8 | #include <boost/config.hpp> |
9 | #if !defined(BOOST_NO_CXX11_SMART_PTR) |
10 | #include <boost/core/lightweight_test.hpp> |
11 | #include <boost/smart_ptr/make_unique.hpp> |
12 | |
13 | class type { |
14 | public: |
15 | static unsigned instances; |
16 | |
17 | type() { |
18 | if (instances == 5) { |
19 | throw true; |
20 | } |
21 | ++instances; |
22 | } |
23 | |
24 | ~type() { |
25 | --instances; |
26 | } |
27 | |
28 | private: |
29 | type(const type&); |
30 | type& operator=(const type&); |
31 | }; |
32 | |
33 | unsigned type::instances = 0; |
34 | |
35 | int main() |
36 | { |
37 | BOOST_TEST(type::instances == 0); |
38 | try { |
39 | boost::make_unique<type[]>(size: 6); |
40 | BOOST_ERROR("make_unique did not throw"); |
41 | } catch (...) { |
42 | BOOST_TEST(type::instances == 0); |
43 | } |
44 | BOOST_TEST(type::instances == 0); |
45 | try { |
46 | boost::make_unique<type[][2]>(size: 3); |
47 | BOOST_ERROR("make_unique did not throw"); |
48 | } catch (...) { |
49 | BOOST_TEST(type::instances == 0); |
50 | } |
51 | BOOST_TEST(type::instances == 0); |
52 | try { |
53 | boost::make_unique_noinit<type[]>(size: 6); |
54 | BOOST_ERROR("make_unique_noinit did not throw"); |
55 | } catch (...) { |
56 | BOOST_TEST(type::instances == 0); |
57 | } |
58 | BOOST_TEST(type::instances == 0); |
59 | try { |
60 | boost::make_unique_noinit<type[][2]>(size: 3); |
61 | BOOST_ERROR("make_unique_noinit did not throw"); |
62 | } catch (...) { |
63 | BOOST_TEST(type::instances == 0); |
64 | } |
65 | return boost::report_errors(); |
66 | } |
67 | #else |
68 | int main() |
69 | { |
70 | return 0; |
71 | } |
72 | #endif |
73 |