diff --git a/include/boost/type_traits/has_nothrow_destructor.hpp b/include/boost/type_traits/has_nothrow_destructor.hpp index e510ece..a3cf832 100644 --- a/include/boost/type_traits/has_nothrow_destructor.hpp +++ b/include/boost/type_traits/has_nothrow_destructor.hpp @@ -11,10 +11,36 @@ #include +#if !defined(BOOST_NO_CXX11_NOEXCEPT) + +#include +#include + +namespace boost{ + + namespace detail{ + + template + struct has_nothrow_destructor_imp : public boost::integral_constant{}; + template + struct has_nothrow_destructor_imp : public boost::integral_constant()->~T())>{}; + + } + + template struct has_nothrow_destructor : public detail::has_nothrow_destructor_imp::value>{}; + template struct has_nothrow_destructor : public has_nothrow_destructor{}; + template struct has_nothrow_destructor : public integral_constant{}; + template struct has_nothrow_destructor : public integral_constant{}; + +} +#else + namespace boost { template struct has_nothrow_destructor : public ::boost::has_trivial_destructor {}; } // namespace boost +#endif + #endif // BOOST_TT_HAS_NOTHROW_DESTRUCTOR_HPP_INCLUDED diff --git a/test/has_nothrow_destructor_test.cpp b/test/has_nothrow_destructor_test.cpp new file mode 100644 index 0000000..74f31bf --- /dev/null +++ b/test/has_nothrow_destructor_test.cpp @@ -0,0 +1,219 @@ + +// (C) Copyright John Maddock 2000. +// Use, modification and distribution are subject to 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 "test.hpp" +#include "check_integral_constant.hpp" +#ifdef TEST_STD +# include +#else +# include +#endif + +#ifdef BOOST_MSVC +#pragma warning(disable:4290) // exception spec ignored +#endif + +struct nothrow_destruct +{ + nothrow_destruct(int); + ~nothrow_destruct()throw(); +}; + +#if !defined(BOOST_NO_CXX11_NOEXCEPT) + +struct noexcept_destruct +{ + noexcept_destruct(int); + ~noexcept_destruct()noexcept; +}; + +#endif + +struct throwing_base +{ + ~throwing_base() throw(int); +}; + +struct throwing_derived : public throwing_base {}; + +struct throwing_contained{ throwing_base data; }; + +TT_TEST_BEGIN(has_nothrow_destructor) + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +#ifdef BOOST_HAS_LONG_LONG + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor< ::boost::ulong_long_type>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor< ::boost::long_long_type>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor< ::boost::ulong_long_type const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor< ::boost::long_long_type const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor< ::boost::ulong_long_type volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor< ::boost::long_long_type volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor< ::boost::ulong_long_type const volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor< ::boost::long_long_type const volatile>::value, true); + +#endif + +#ifdef BOOST_HAS_MS_INT64 + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int8>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int8 const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int8 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int8 const volatile>::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int16>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int16 const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int16 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int16 const volatile>::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int32>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int32 const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int32 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int32 const volatile>::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int64>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int64 const>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int64 volatile>::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor<__int64 const volatile>::value, true); + +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +// +// These are commented out for now because it's not clear what the semantics should be: +// on the one hand references always have trivial destructors (in the sense that there is +// nothing to destruct), on the other hand the thing referenced may not have a trivial +// destructor, it really depends upon the users code as to what should happen here: +// +//BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, false); +//BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, false); +// +// Destructors on UDT's are non-throwing by default, unless they are explicity marked otherwise: +// +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, false); +// cases we would like to succeed but can't implement in the language: +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); + +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor >::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor >::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor >::value, true, false); +BOOST_CHECK_SOFT_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor >::value, true, false); + +#if !defined(BOOST_NO_CXX11_NOEXCEPT) + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, true); + +#endif + +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_destructor::value, false); + +TT_TEST_END + + +