Use throw() in place of noexcept on msvc-11.0,12.0 for the standard nothrow traits

This commit is contained in:
Peter Dimov
2016-11-08 18:42:51 +02:00
parent a7fbb0a841
commit 3e61a63f60
10 changed files with 161 additions and 26 deletions

View File

@ -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 <boost/config.hpp>
#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

View File

@ -15,6 +15,7 @@
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>
@ -25,20 +26,20 @@ template<class T> 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<T> newer throws, so this call also must not throw
~enable_shared_from_this() BOOST_SP_NOEXCEPT // ~weak_ptr<T> newer throws, so this call also must not throw
{
}

View File

@ -19,6 +19,7 @@
#include <boost/detail/workaround.hpp>
#include <boost/smart_ptr/detail/sp_convertible.hpp>
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
#include <boost/config/no_tr1/functional.hpp> // 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;

View File

@ -15,6 +15,7 @@
#include <boost/assert.hpp>
#include <boost/checked_delete.hpp>
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
#include <boost/detail/workaround.hpp>
@ -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 );

View File

@ -16,6 +16,7 @@
#include <boost/checked_delete.hpp>
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
#include <boost/detail/workaround.hpp>
#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 );

View File

@ -24,6 +24,7 @@
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/detail/shared_count.hpp>
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
#include <boost/detail/workaround.hpp>
#include <cstddef> // 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;

View File

@ -30,6 +30,7 @@
#include <boost/smart_ptr/detail/sp_convertible.hpp>
#include <boost/smart_ptr/detail/sp_nullptr_t.hpp>
#include <boost/smart_ptr/detail/sp_disable_deprecated.hpp>
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
#if !defined(BOOST_SP_NO_ATOMIC_ACCESS)
#include <boost/smart_ptr/detail/spinlock_pool.hpp>
@ -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;

View File

@ -16,6 +16,7 @@
#include <memory> // boost.TR1 include order fix
#include <boost/smart_ptr/detail/shared_count.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/detail/sp_noexcept.hpp>
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;

View File

@ -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 ]
;
}

96
test/sp_nothrow_test.cpp Normal file
View File

@ -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 <boost/config.hpp>
#if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS )
int main()
{
}
#else
#include <boost/shared_ptr.hpp>
#include <boost/shared_array.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_array.hpp>
#include <boost/intrusive_ptr.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
template<class T> void test_copy()
{
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_constructible<T> ));
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_copy_assignable<T> ));
}
template<class T> void test_move()
{
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible<T> ));
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable<T> ));
}
template<class T> void test_default()
{
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_default_constructible<T> ));
}
template<class T> void test_destroy()
{
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_destructible<T> ));
}
template<class T> void test_cmd()
{
test_copy<T>();
test_move<T>();
test_default<T>();
}
struct X
{
};
struct Y: public boost::enable_shared_from_this<Y>
{
};
int main()
{
test_cmd< boost::shared_ptr<X> >();
test_cmd< boost::shared_array<X> >();
test_cmd< boost::weak_ptr<X> >();
test_copy< Y >();
test_default< Y >();
test_destroy< Y >();
// test_move< Y >();
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_constructible<Y> ));
#if !( defined( BOOST_MSVC ) && BOOST_MSVC == 1700 )
BOOST_TEST_TRAIT_TRUE(( std::is_nothrow_move_assignable<Y> ));
#endif
test_default< boost::scoped_ptr<X> >();
test_default< boost::scoped_array<X> >();
test_move< boost::intrusive_ptr<X> >();
test_default< boost::intrusive_ptr<X> >();
return boost::report_errors();
}
#endif // #if defined( BOOST_NO_CXX11_HDR_TYPE_TRAITS )