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