diff --git a/include/boost/smart_ptr/detail/sp_noexcept.hpp b/include/boost/smart_ptr/detail/sp_noexcept.hpp new file mode 100644 index 0000000..6818dce --- /dev/null +++ b/include/boost/smart_ptr/detail/sp_noexcept.hpp @@ -0,0 +1,30 @@ +#ifndef BOOST_SMART_PTR_DETAIL_SP_NOEXCEPT_HPP_INCLUDED +#define BOOST_SMART_PTR_DETAIL_SP_NOEXCEPT_HPP_INCLUDED + +// MS compatible compilers support #pragma once + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +// detail/sp_noexcept.hpp +// +// Copyright 2016 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +#include + +#if defined( BOOST_MSVC ) && BOOST_MSVC >= 1700 && BOOST_MSVC < 1900 + +#define BOOST_SP_NOEXCEPT BOOST_NOEXCEPT_OR_NOTHROW + +#else + +#define BOOST_SP_NOEXCEPT BOOST_NOEXCEPT + +#endif + +#endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_NOEXCEPT_HPP_INCLUDED diff --git a/include/boost/smart_ptr/enable_shared_from_this.hpp b/include/boost/smart_ptr/enable_shared_from_this.hpp index 4e3f243..642403a 100644 --- a/include/boost/smart_ptr/enable_shared_from_this.hpp +++ b/include/boost/smart_ptr/enable_shared_from_this.hpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -25,20 +26,20 @@ template class enable_shared_from_this { protected: - enable_shared_from_this() BOOST_NOEXCEPT + enable_shared_from_this() BOOST_SP_NOEXCEPT { } - enable_shared_from_this(enable_shared_from_this const &) BOOST_NOEXCEPT + enable_shared_from_this(enable_shared_from_this const &) BOOST_SP_NOEXCEPT { } - enable_shared_from_this & operator=(enable_shared_from_this const &) BOOST_NOEXCEPT + enable_shared_from_this & operator=(enable_shared_from_this const &) BOOST_SP_NOEXCEPT { return *this; } - ~enable_shared_from_this() BOOST_NOEXCEPT // ~weak_ptr newer throws, so this call also must not throw + ~enable_shared_from_this() BOOST_SP_NOEXCEPT // ~weak_ptr newer throws, so this call also must not throw { } diff --git a/include/boost/smart_ptr/intrusive_ptr.hpp b/include/boost/smart_ptr/intrusive_ptr.hpp index 1e93397..0e46212 100644 --- a/include/boost/smart_ptr/intrusive_ptr.hpp +++ b/include/boost/smart_ptr/intrusive_ptr.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include // for std::less @@ -59,7 +60,7 @@ public: typedef T element_type; - BOOST_CONSTEXPR intrusive_ptr() BOOST_NOEXCEPT : px( 0 ) + BOOST_CONSTEXPR intrusive_ptr() BOOST_SP_NOEXCEPT : px( 0 ) { } @@ -111,12 +112,12 @@ public: #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) - intrusive_ptr(intrusive_ptr && rhs) BOOST_NOEXCEPT : px( rhs.px ) + intrusive_ptr(intrusive_ptr && rhs) BOOST_SP_NOEXCEPT : px( rhs.px ) { rhs.px = 0; } - intrusive_ptr & operator=(intrusive_ptr && rhs) BOOST_NOEXCEPT + intrusive_ptr & operator=(intrusive_ptr && rhs) BOOST_SP_NOEXCEPT { this_type( static_cast< intrusive_ptr && >( rhs ) ).swap(*this); return *this; diff --git a/include/boost/smart_ptr/scoped_array.hpp b/include/boost/smart_ptr/scoped_array.hpp index e395e28..f847c09 100644 --- a/include/boost/smart_ptr/scoped_array.hpp +++ b/include/boost/smart_ptr/scoped_array.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -54,7 +55,7 @@ public: typedef T element_type; - explicit scoped_array( T * p = 0 ) BOOST_NOEXCEPT : px( p ) + explicit scoped_array( T * p = 0 ) BOOST_SP_NOEXCEPT : px( p ) { #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) boost::sp_array_constructor_hook( px ); diff --git a/include/boost/smart_ptr/scoped_ptr.hpp b/include/boost/smart_ptr/scoped_ptr.hpp index d5d8720..8fd8a18 100644 --- a/include/boost/smart_ptr/scoped_ptr.hpp +++ b/include/boost/smart_ptr/scoped_ptr.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #ifndef BOOST_NO_AUTO_PTR @@ -62,7 +63,7 @@ public: typedef T element_type; - explicit scoped_ptr( T * p = 0 ): px( p ) // never throws + explicit scoped_ptr( T * p = 0 ) BOOST_SP_NOEXCEPT : px( p ) // never throws { #if defined(BOOST_SP_ENABLE_DEBUG_HOOKS) boost::sp_scalar_constructor_hook( px ); diff --git a/include/boost/smart_ptr/shared_array.hpp b/include/boost/smart_ptr/shared_array.hpp index fd58071..2e5cb13 100644 --- a/include/boost/smart_ptr/shared_array.hpp +++ b/include/boost/smart_ptr/shared_array.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include // for std::ptrdiff_t @@ -53,13 +54,13 @@ public: typedef T element_type; - shared_array() BOOST_NOEXCEPT : px( 0 ), pn() + shared_array() BOOST_SP_NOEXCEPT : px( 0 ), pn() { } #if !defined( BOOST_NO_CXX11_NULLPTR ) - shared_array( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn() + shared_array( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn() { } @@ -95,11 +96,11 @@ public: // ... except in C++0x, move disables the implicit copy - shared_array( shared_array const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn ) + shared_array( shared_array const & r ) BOOST_SP_NOEXCEPT : px( r.px ), pn( r.pn ) { } - shared_array( shared_array && r ) BOOST_NOEXCEPT : px( r.px ), pn() + shared_array( shared_array && r ) BOOST_SP_NOEXCEPT : px( r.px ), pn() { pn.swap( r.pn ); r.px = 0; @@ -133,7 +134,7 @@ public: // assignment - shared_array & operator=( shared_array const & r ) BOOST_NOEXCEPT + shared_array & operator=( shared_array const & r ) BOOST_SP_NOEXCEPT { this_type( r ).swap( *this ); return *this; @@ -152,7 +153,7 @@ public: #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) - shared_array & operator=( shared_array && r ) BOOST_NOEXCEPT + shared_array & operator=( shared_array && r ) BOOST_SP_NOEXCEPT { this_type( static_cast< shared_array && >( r ) ).swap( *this ); return *this; diff --git a/include/boost/smart_ptr/shared_ptr.hpp b/include/boost/smart_ptr/shared_ptr.hpp index 77f68be..deb3fec 100644 --- a/include/boost/smart_ptr/shared_ptr.hpp +++ b/include/boost/smart_ptr/shared_ptr.hpp @@ -30,6 +30,7 @@ #include #include #include +#include #if !defined(BOOST_SP_NO_ATOMIC_ACCESS) #include @@ -344,13 +345,13 @@ public: typedef typename boost::detail::sp_element< T >::type element_type; - shared_ptr() BOOST_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+ + shared_ptr() BOOST_SP_NOEXCEPT : px( 0 ), pn() // never throws in 1.30+ { } #if !defined( BOOST_NO_CXX11_NULLPTR ) - shared_ptr( boost::detail::sp_nullptr_t ) BOOST_NOEXCEPT : px( 0 ), pn() // never throws + shared_ptr( boost::detail::sp_nullptr_t ) BOOST_SP_NOEXCEPT : px( 0 ), pn() // never throws { } @@ -402,7 +403,7 @@ public: // ... except in C++0x, move disables the implicit copy - shared_ptr( shared_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn ) + shared_ptr( shared_ptr const & r ) BOOST_SP_NOEXCEPT : px( r.px ), pn( r.pn ) { } @@ -521,7 +522,7 @@ public: // assignment - shared_ptr & operator=( shared_ptr const & r ) BOOST_NOEXCEPT + shared_ptr & operator=( shared_ptr const & r ) BOOST_SP_NOEXCEPT { this_type(r).swap(*this); return *this; @@ -605,7 +606,7 @@ public: #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) - shared_ptr( shared_ptr && r ) BOOST_NOEXCEPT : px( r.px ), pn() + shared_ptr( shared_ptr && r ) BOOST_SP_NOEXCEPT : px( r.px ), pn() { pn.swap( r.pn ); r.px = 0; @@ -629,7 +630,7 @@ public: r.px = 0; } - shared_ptr & operator=( shared_ptr && r ) BOOST_NOEXCEPT + shared_ptr & operator=( shared_ptr && r ) BOOST_SP_NOEXCEPT { this_type( static_cast< shared_ptr && >( r ) ).swap( *this ); return *this; diff --git a/include/boost/smart_ptr/weak_ptr.hpp b/include/boost/smart_ptr/weak_ptr.hpp index e3e9ad9..f3411f7 100644 --- a/include/boost/smart_ptr/weak_ptr.hpp +++ b/include/boost/smart_ptr/weak_ptr.hpp @@ -16,6 +16,7 @@ #include // boost.TR1 include order fix #include #include +#include namespace boost { @@ -31,7 +32,7 @@ public: typedef typename boost::detail::sp_element< T >::type element_type; - weak_ptr() BOOST_NOEXCEPT : px(0), pn() // never throws in 1.30+ + weak_ptr() BOOST_SP_NOEXCEPT : px(0), pn() // never throws in 1.30+ { } @@ -41,11 +42,11 @@ public: // ... except in C++0x, move disables the implicit copy - weak_ptr( weak_ptr const & r ) BOOST_NOEXCEPT : px( r.px ), pn( r.pn ) + weak_ptr( weak_ptr const & r ) BOOST_SP_NOEXCEPT : px( r.px ), pn( r.pn ) { } - weak_ptr & operator=( weak_ptr const & r ) BOOST_NOEXCEPT + weak_ptr & operator=( weak_ptr const & r ) BOOST_SP_NOEXCEPT { px = r.px; pn = r.pn; @@ -106,13 +107,13 @@ public: // for better efficiency in the T == Y case weak_ptr( weak_ptr && r ) - BOOST_NOEXCEPT : px( r.px ), pn( static_cast< boost::detail::weak_count && >( r.pn ) ) + BOOST_SP_NOEXCEPT : px( r.px ), pn( static_cast< boost::detail::weak_count && >( r.pn ) ) { r.px = 0; } // for better efficiency in the T == Y case - weak_ptr & operator=( weak_ptr && r ) BOOST_NOEXCEPT + weak_ptr & operator=( weak_ptr && r ) BOOST_SP_NOEXCEPT { this_type( static_cast< weak_ptr && >( r ) ).swap( *this ); return *this; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7c31ce5..a9546db 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -201,5 +201,7 @@ import testing ; [ compile-fail pointer_cast_dy_fail.cpp ] [ compile-fail pointer_cast_dy_fail2.cpp ] [ compile-fail pointer_cast_dy_fail3.cpp ] + + [ run sp_nothrow_test.cpp ] ; } diff --git a/test/sp_nothrow_test.cpp b/test/sp_nothrow_test.cpp new file mode 100644 index 0000000..156e72e --- /dev/null +++ b/test/sp_nothrow_test.cpp @@ -0,0 +1,96 @@ +// +// sp_nothrow_test.cpp +// +// Copyright 2016 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include + +#if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS ) + +int main() +{ +} + +#else + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template void test_copy() +{ + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_constructible )); + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_assignable )); +} + +template void test_move() +{ + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible )); + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable )); +} + +template void test_default() +{ + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_default_constructible )); +} + +template void test_destroy() +{ + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_destructible )); +} + +template void test_cmd() +{ + test_copy(); + test_move(); + test_default(); +} + +struct X +{ +}; + +struct Y: public boost::enable_shared_from_this +{ +}; + +int main() +{ + test_cmd< boost::shared_ptr >(); + test_cmd< boost::shared_array >(); + test_cmd< boost::weak_ptr >(); + + test_copy< Y >(); + test_default< Y >(); + test_destroy< Y >(); + + // test_move< Y >(); + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible )); + +#if !( defined( BOOST_MSVC ) && BOOST_MSVC == 1700 ) + + BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable )); + +#endif + + test_default< boost::scoped_ptr >(); + test_default< boost::scoped_array >(); + + test_move< boost::intrusive_ptr >(); + test_default< boost::intrusive_ptr >(); + + return boost::report_errors(); +} + +#endif // #if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS )