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

source code of boost/libs/smart_ptr/test/make_shared_array_throws_test.cpp