From 1335987b925f18e59b97533259ee9c7d8377524b Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 7 Dec 2009 13:06:52 +0000 Subject: [PATCH] Merge type_traits bug fixes from Trunk. [SVN r58216] --- .../boost/type_traits/has_new_operator.hpp | 101 +++++++++++------- include/boost/type_traits/intrinsics.hpp | 2 +- include/boost/type_traits/is_signed.hpp | 10 +- include/boost/type_traits/is_unsigned.hpp | 11 +- test/aligned_storage_empy_test.cpp | 21 ++-- test/has_operator_new_test.cpp | 11 ++ test/is_abstract_test.cpp | 4 + test/test.hpp | 4 + 8 files changed, 113 insertions(+), 51 deletions(-) mode change 100755 => 100644 test/is_abstract_test.cpp diff --git a/include/boost/type_traits/has_new_operator.hpp b/include/boost/type_traits/has_new_operator.hpp index 6d5351e..2c2c322 100644 --- a/include/boost/type_traits/has_new_operator.hpp +++ b/include/boost/type_traits/has_new_operator.hpp @@ -26,7 +26,7 @@ namespace detail { template struct has_new_operator_impl { template - static type_traits::yes_type check_sig( + static type_traits::yes_type check_sig1( U*, test< void *(*)(std::size_t), @@ -34,64 +34,85 @@ namespace detail { >* = NULL ); template - static type_traits::yes_type check_sig( - U*, - test< - void *(*)(std::size_t, const std::nothrow_t&), - &U::operator new - >* = NULL - ); - template - static type_traits::yes_type check_sig( - U*, - test< - void *(*)(std::size_t, void*), - &U::operator new - >* = NULL - ); - template - static type_traits::no_type check_sig(...); + static type_traits::no_type check_sig1(...); - template - static type_traits::yes_type check_sig2( - U*, - test< - void *(*)(std::size_t), - &U::operator new[] - >* = NULL - ); template static type_traits::yes_type check_sig2( U*, test< void *(*)(std::size_t, const std::nothrow_t&), - &U::operator new[] - >* = NULL - ); - template - static type_traits::yes_type check_sig2( - U*, - test< - void *(*)(std::size_t, void*), - &U::operator new[] + &U::operator new >* = NULL ); template static type_traits::no_type check_sig2(...); + template + static type_traits::yes_type check_sig3( + U*, + test< + void *(*)(std::size_t, void*), + &U::operator new + >* = NULL + ); + template + static type_traits::no_type check_sig3(...); + + + template + static type_traits::yes_type check_sig4( + U*, + test< + void *(*)(std::size_t), + &U::operator new[] + >* = NULL + ); + template + static type_traits::no_type check_sig4(...); + + template + static type_traits::yes_type check_sig5( + U*, + test< + void *(*)(std::size_t, const std::nothrow_t&), + &U::operator new[] + >* = NULL + ); + template + static type_traits::no_type check_sig5(...); + + template + static type_traits::yes_type check_sig6( + U*, + test< + void *(*)(std::size_t, void*), + &U::operator new[] + >* = NULL + ); + template + static type_traits::no_type check_sig6(...); + // GCC2 won't even parse this template if we embed the computation // of s1 in the computation of value. #ifdef __GNUC__ - BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(has_new_operator_impl::template check_sig(0))); + BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(has_new_operator_impl::template check_sig1(0))); BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(has_new_operator_impl::template check_sig2(0))); + BOOST_STATIC_CONSTANT(unsigned, s3 = sizeof(has_new_operator_impl::template check_sig3(0))); + BOOST_STATIC_CONSTANT(unsigned, s4 = sizeof(has_new_operator_impl::template check_sig4(0))); + BOOST_STATIC_CONSTANT(unsigned, s5 = sizeof(has_new_operator_impl::template check_sig5(0))); + BOOST_STATIC_CONSTANT(unsigned, s6 = sizeof(has_new_operator_impl::template check_sig6(0))); #else #if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000) #pragma warning(push) #pragma warning(disable:6334) #endif - BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(check_sig(0))); + BOOST_STATIC_CONSTANT(unsigned, s1 = sizeof(check_sig1(0))); BOOST_STATIC_CONSTANT(unsigned, s2 = sizeof(check_sig2(0))); + BOOST_STATIC_CONSTANT(unsigned, s3 = sizeof(check_sig3(0))); + BOOST_STATIC_CONSTANT(unsigned, s4 = sizeof(check_sig4(0))); + BOOST_STATIC_CONSTANT(unsigned, s5 = sizeof(check_sig5(0))); + BOOST_STATIC_CONSTANT(unsigned, s6 = sizeof(check_sig6(0))); #if BOOST_WORKAROUND(BOOST_MSVC_FULL_VER, >= 140050000) #pragma warning(pop) @@ -100,7 +121,11 @@ namespace detail { BOOST_STATIC_CONSTANT(bool, value = (::boost::type_traits::ice_or< (s1 == sizeof(type_traits::yes_type)), - (s2 == sizeof(type_traits::yes_type)) + (s2 == sizeof(type_traits::yes_type)), + (s3 == sizeof(type_traits::yes_type)), + (s4 == sizeof(type_traits::yes_type)), + (s5 == sizeof(type_traits::yes_type)), + (s6 == sizeof(type_traits::yes_type)) >::value) ); }; diff --git a/include/boost/type_traits/intrinsics.hpp b/include/boost/type_traits/intrinsics.hpp index 74b64a7..8f88036 100644 --- a/include/boost/type_traits/intrinsics.hpp +++ b/include/boost/type_traits/intrinsics.hpp @@ -149,7 +149,7 @@ # define BOOST_IS_CLASS(T) __is_class(T) # define BOOST_IS_ENUM(T) __is_enum(T) # define BOOST_IS_POLYMORPHIC(T) __is_polymorphic(T) -# if !defined(unix) || defined(__LP64__) +# if (!defined(unix) && !defined(__unix__)) || defined(__LP64__) // GCC sometimes lies about alignment requirements // of type double on 32-bit unix platforms, use the // old implementation instead in that case: diff --git a/include/boost/type_traits/is_signed.hpp b/include/boost/type_traits/is_signed.hpp index e06b47c..bf7bbfd 100644 --- a/include/boost/type_traits/is_signed.hpp +++ b/include/boost/type_traits/is_signed.hpp @@ -26,11 +26,19 @@ namespace detail{ #if !(defined(__EDG_VERSION__) && __EDG_VERSION__ <= 238) +template +struct is_signed_values +{ + typedef typename remove_cv::type no_cv_t; + BOOST_STATIC_CONSTANT(no_cv_t, minus_one = (static_cast(-1))); + BOOST_STATIC_CONSTANT(no_cv_t, zero = (static_cast(0))); +}; + template struct is_signed_helper { typedef typename remove_cv::type no_cv_t; - BOOST_STATIC_CONSTANT(bool, value = (!(static_cast(-1) > 0))); + BOOST_STATIC_CONSTANT(bool, value = (!(::boost::detail::is_signed_values::minus_one > boost::detail::is_signed_values::zero))); }; template diff --git a/include/boost/type_traits/is_unsigned.hpp b/include/boost/type_traits/is_unsigned.hpp index 4866486..98baf4e 100644 --- a/include/boost/type_traits/is_unsigned.hpp +++ b/include/boost/type_traits/is_unsigned.hpp @@ -27,10 +27,17 @@ namespace detail{ #if !(defined(__EDG_VERSION__) && __EDG_VERSION__ <= 238) template -struct is_ununsigned_helper +struct is_unsigned_values { typedef typename remove_cv::type no_cv_t; - BOOST_STATIC_CONSTANT(bool, value = (static_cast(-1) > 0)); + BOOST_STATIC_CONSTANT(no_cv_t, minus_one = (static_cast(-1))); + BOOST_STATIC_CONSTANT(no_cv_t, zero = (static_cast(0))); +}; + +template +struct is_ununsigned_helper +{ + BOOST_STATIC_CONSTANT(bool, value = (::boost::detail::is_unsigned_values::minus_one > ::boost::detail::is_unsigned_values::zero)); }; template diff --git a/test/aligned_storage_empy_test.cpp b/test/aligned_storage_empy_test.cpp index 6772cc0..28e9e20 100644 --- a/test/aligned_storage_empy_test.cpp +++ b/test/aligned_storage_empy_test.cpp @@ -22,7 +22,7 @@ namespace struct alignment_implementation1 { boost::detail::aligned_storage::aligned_storage_imp type; - const void* address() const { return this; } + const void* address() const { return type.address(); } }; template< unsigned N, unsigned Alignment > @@ -39,24 +39,24 @@ namespace }; template< unsigned N, class T > - const void* get_address1() + std::ptrdiff_t get_address1() { - alignment_implementation1::value> imp1; - return imp1.address(); + static alignment_implementation1::value> imp1; + return static_cast(imp1.address()) - reinterpret_cast(&imp1); } template< unsigned N, class T > - const void* get_address2() + std::ptrdiff_t get_address2() { - alignment_implementation2::value> imp2; - return imp2.address(); + static alignment_implementation2::value> imp2; + return static_cast(imp2.address()) - reinterpret_cast(&imp2); } template< class T > void check() { - const void* addr1 = get_address1<0,T>(); - const void* addr2 = get_address2<0,T>(); + std::ptrdiff_t addr1 = get_address1<0,T>(); + std::ptrdiff_t addr2 = get_address2<0,T>(); // // @remark: only the empty case differs // @@ -101,6 +101,9 @@ check(); #ifdef BOOST_HAS_MS_INT64 check<__int64>(); #endif +#ifdef BOOST_HAS_LONG_LONG +check(); +#endif check(); check(); diff --git a/test/has_operator_new_test.cpp b/test/has_operator_new_test.cpp index d9e9349..cd7b863 100644 --- a/test/has_operator_new_test.cpp +++ b/test/has_operator_new_test.cpp @@ -33,6 +33,16 @@ struct class_with_new_op6 { void* operator new[] (std::size_t size, void* ptr); }; +struct class_with_all_ops +{ + void * operator new(std::size_t); + void* operator new(std::size_t size, const std::nothrow_t&); + void* operator new[](std::size_t size); + void* operator new[](std::size_t size, const std::nothrow_t&); + void* operator new (std::size_t size, void* ptr); + void* operator new[] (std::size_t size, void* ptr); +}; + TT_TEST_BEGIN(has_new_operator) BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); @@ -42,6 +52,7 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, true); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_new_operator::value, false); diff --git a/test/is_abstract_test.cpp b/test/is_abstract_test.cpp old mode 100755 new mode 100644 index 2d2079a..3f63aee --- a/test/is_abstract_test.cpp +++ b/test/is_abstract_test.cpp @@ -13,6 +13,10 @@ # include #endif +#ifdef BOOST_MSVC +#pragma warning(disable: 4505) +#endif + struct TestA {}; struct TestB { virtual void foo(void) = 0; }; diff --git a/test/test.hpp b/test/test.hpp index 47c3333..f31452b 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -407,6 +407,10 @@ struct wrap { T t; int j; +protected: + wrap(); + wrap(const wrap&); + wrap& operator=(const wrap&); };