sp_constexpr_test.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // sp_constexpr_test.cpp
  3. //
  4. // Copyright 2017 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //
  10. #include <boost/config.hpp>
  11. #include <boost/detail/workaround.hpp>
  12. #define HAVE_CONSTEXPR_INIT
  13. #if defined( BOOST_NO_CXX11_CONSTEXPR )
  14. # undef HAVE_CONSTEXPR_INIT
  15. #endif
  16. #if BOOST_WORKAROUND( BOOST_MSVC, < 1930 )
  17. # undef HAVE_CONSTEXPR_INIT
  18. #endif
  19. #if defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR )
  20. # undef HAVE_CONSTEXPR_INIT
  21. #endif
  22. #if !defined( HAVE_CONSTEXPR_INIT )
  23. int main()
  24. {
  25. }
  26. #else
  27. #include <boost/shared_ptr.hpp>
  28. #include <boost/weak_ptr.hpp>
  29. #include <boost/enable_shared_from_this.hpp>
  30. #include <boost/core/lightweight_test.hpp>
  31. struct X: public boost::enable_shared_from_this<X>
  32. {
  33. };
  34. struct Z
  35. {
  36. Z();
  37. };
  38. static Z z;
  39. static boost::shared_ptr<X> p1;
  40. static boost::weak_ptr<X> p2;
  41. #if !defined( BOOST_NO_CXX11_NULLPTR )
  42. static boost::shared_ptr<X> p3( nullptr );
  43. #endif
  44. Z::Z()
  45. {
  46. p1.reset( new X );
  47. p2 = p1;
  48. #if !defined( BOOST_NO_CXX11_NULLPTR )
  49. p3.reset( new X );
  50. #endif
  51. }
  52. int main()
  53. {
  54. BOOST_TEST( p1.get() != 0 );
  55. BOOST_TEST_EQ( p1.use_count(), 1 );
  56. BOOST_TEST_EQ( p2.use_count(), 1 );
  57. BOOST_TEST_EQ( p2.lock(), p1 );
  58. #if !defined( BOOST_NO_CXX11_NULLPTR )
  59. BOOST_TEST( p3.get() != 0 );
  60. BOOST_TEST_EQ( p3.use_count(), 1 );
  61. #endif
  62. return boost::report_errors();
  63. }
  64. #endif // #if defined( BOOST_NO_CXX11_CONSEXPR )