1 /* 2 Copyright 2017 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_RVALUE_REFERENCES) && \ 10 !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 11 #include <boost/detail/lightweight_test.hpp> 12 #include <boost/smart_ptr/make_local_shared.hpp> 13 14 class type { 15 public: 16 static unsigned instances; 17 type()18 type() { 19 if (instances == 5) { 20 throw true; 21 } 22 ++instances; 23 } 24 ~type()25 ~type() { 26 --instances; 27 } 28 29 private: 30 type(const type&); 31 type& operator=(const type&); 32 }; 33 34 unsigned type::instances = 0; 35 main()36int main() 37 { 38 try { 39 boost::make_local_shared<type[]>(6); 40 BOOST_ERROR("make_local_shared did not throw"); 41 } catch (...) { 42 BOOST_TEST(type::instances == 0); 43 } 44 try { 45 boost::make_local_shared<type[][2]>(3); 46 BOOST_ERROR("make_local_shared did not throw"); 47 } catch (...) { 48 BOOST_TEST(type::instances == 0); 49 } 50 try { 51 boost::make_local_shared<type[6]>(); 52 BOOST_ERROR("make_local_shared did not throw"); 53 } catch (...) { 54 BOOST_TEST(type::instances == 0); 55 } 56 try { 57 boost::make_local_shared<type[3][2]>(); 58 BOOST_ERROR("make_local_shared did not throw"); 59 } catch (...) { 60 BOOST_TEST(type::instances == 0); 61 } 62 try { 63 boost::make_local_shared_noinit<type[]>(6); 64 BOOST_ERROR("make_local_shared_noinit did not throw"); 65 } catch (...) { 66 BOOST_TEST(type::instances == 0); 67 } 68 try { 69 boost::make_local_shared_noinit<type[][2]>(3); 70 BOOST_ERROR("make_local_shared_noinit did not throw"); 71 } catch (...) { 72 BOOST_TEST(type::instances == 0); 73 } 74 try { 75 boost::make_local_shared_noinit<type[6]>(); 76 BOOST_ERROR("make_local_shared_noinit did not throw"); 77 } catch (...) { 78 BOOST_TEST(type::instances == 0); 79 } 80 try { 81 boost::make_local_shared_noinit<type[3][2]>(); 82 BOOST_ERROR("make_local_shared_noinit did not throw"); 83 } catch (...) { 84 BOOST_TEST(type::instances == 0); 85 } 86 return boost::report_errors(); 87 } 88 #else main()89int main() 90 { 91 return 0; 92 } 93 #endif 94