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