make_unique_throws_test.cpp 914 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. Copyright 2014 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/config.hpp>
  8. #if !defined(BOOST_NO_CXX11_SMART_PTR)
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/smart_ptr/make_unique.hpp>
  11. class type {
  12. public:
  13. static unsigned instances;
  14. type() {
  15. if (instances == 0) {
  16. throw true;
  17. }
  18. ++instances;
  19. }
  20. ~type() {
  21. --instances;
  22. }
  23. private:
  24. type(const type&);
  25. type& operator=(const type&);
  26. };
  27. unsigned type::instances = 0;
  28. int main()
  29. {
  30. BOOST_TEST(type::instances == 0);
  31. try {
  32. boost::make_unique<type>();
  33. BOOST_ERROR("make_unique did not throw");
  34. } catch (...) {
  35. BOOST_TEST(type::instances == 0);
  36. }
  37. return boost::report_errors();
  38. }
  39. #else
  40. int main()
  41. {
  42. return 0;
  43. }
  44. #endif