From 13ca0cf6982efbdbf65b80ec18fbd861ea821a14 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Mon, 12 Oct 2009 11:00:02 +0000 Subject: [PATCH] Fixes #3401. [SVN r56730] --- .../boost/type_traits/has_new_operator.hpp | 101 +++++++++++------- test/has_operator_new_test.cpp | 11 ++ 2 files changed, 74 insertions(+), 38 deletions(-) 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/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);