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_object.hpp> 13 14 class type { 15 public: 16 static unsigned int instances; 17 type()18 explicit type() { 19 if (instances == 0) { 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>(); 40 BOOST_ERROR("make_unique did not throw"); 41 } catch (...) { 42 BOOST_TEST(type::instances == 0); 43 } 44 45 return boost::report_errors(); 46 } 47 #else 48 main()49int main() { 50 return 0; 51 } 52 53 #endif 54