make_local_shared_array_throws_test.cpp 2.2 KB

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