1 /* 2 * Copyright (c) 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/config.hpp> 10 #if !defined(BOOST_NO_CXX11_SMART_PTR) 11 #include <boost/detail/lightweight_test.hpp> 12 #include <boost/smart_ptr/make_unique_array.hpp> 13 14 class type { 15 public: 16 static unsigned int instances; 17 type()18 explicit 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 int type::instances = 0; 35 main()36int main() { 37 BOOST_TEST(type::instances == 0); 38 try { 39 boost::make_unique<type[]>(6); 40 BOOST_ERROR("make_unique did not throw"); 41 } catch (...) { 42 BOOST_TEST(type::instances == 0); 43 } 44 45 BOOST_TEST(type::instances == 0); 46 try { 47 boost::make_unique<type[][2]>(3); 48 BOOST_ERROR("make_unique did not throw"); 49 } catch (...) { 50 BOOST_TEST(type::instances == 0); 51 } 52 53 BOOST_TEST(type::instances == 0); 54 try { 55 boost::make_unique_noinit<type[]>(6); 56 BOOST_ERROR("make_unique_noinit did not throw"); 57 } catch (...) { 58 BOOST_TEST(type::instances == 0); 59 } 60 61 BOOST_TEST(type::instances == 0); 62 try { 63 boost::make_unique_noinit<type[][2]>(3); 64 BOOST_ERROR("make_unique_noinit did not throw"); 65 } catch (...) { 66 BOOST_TEST(type::instances == 0); 67 } 68 69 return boost::report_errors(); 70 } 71 #else 72 main()73int main() { 74 return 0; 75 } 76 77 #endif 78