atomic_sp_constexpr_test.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // atomic_sp_constexpr_test.cpp
  3. //
  4. // Copyright 2017, 2018 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/config/workaround.hpp>
  12. #include <boost/config/pragma_message.hpp>
  13. #include <boost/config/helper_macros.hpp>
  14. #if defined( BOOST_NO_CXX11_CONSTEXPR )
  15. BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_CONSTEXPR")
  16. int main() {}
  17. #elif BOOST_WORKAROUND( BOOST_MSVC, < 1930 )
  18. // MSVC does not implement static initialization for constexpr constructors
  19. BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_MSVC < 1930")
  20. int main() {}
  21. #elif defined(__clang__) && defined( BOOST_NO_CXX14_CONSTEXPR )
  22. // Clang only implements static initialization for constexpr in C++14 mode
  23. BOOST_PRAGMA_MESSAGE("Skipping test due to __clang__ and BOOST_NO_CXX14_CONSTEXPR")
  24. int main() {}
  25. #elif defined( _LIBCPP_VERSION ) && ( _LIBCPP_VERSION < 6000 )
  26. // in libc++, atomic_flag has a non-constexpr constructor from bool
  27. BOOST_PRAGMA_MESSAGE("Skipping test due to _LIBCPP_VERSION " BOOST_STRINGIZE(_LIBCPP_VERSION))
  28. int main() {}
  29. #elif defined( BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX )
  30. BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX")
  31. int main() {}
  32. #else
  33. #include <boost/smart_ptr/atomic_shared_ptr.hpp>
  34. #include <boost/core/lightweight_test.hpp>
  35. struct X
  36. {
  37. };
  38. struct Z
  39. {
  40. Z();
  41. };
  42. static Z z;
  43. static boost::atomic_shared_ptr<X> p1;
  44. Z::Z()
  45. {
  46. p1 = boost::shared_ptr<X>( new X );
  47. }
  48. int main()
  49. {
  50. boost::shared_ptr<X> p2 = p1;
  51. BOOST_TEST( p2.get() != 0 );
  52. BOOST_TEST_EQ( p2.use_count(), 2 );
  53. return boost::report_errors();
  54. }
  55. #endif