From b21b0f04769f3083c9a4a8639170f0b800b2df3e Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Tue, 9 Jun 2015 18:48:46 +0100 Subject: [PATCH] Fix test case: arrays are not explicitly copyable --- doc/has_nothrow_copy.qbk | 15 ++++-------- .../boost/type_traits/has_nothrow_copy.hpp | 23 +++++++++++++++++++ .../boost/type_traits/has_trivial_copy.hpp | 22 +++++------------- test/has_nothrow_copy_test.cpp | 11 +++++---- test/has_trivial_copy_test.cpp | 7 +++--- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/doc/has_nothrow_copy.qbk b/doc/has_nothrow_copy.qbk index c00a5a3..28c251e 100644 --- a/doc/has_nothrow_copy.qbk +++ b/doc/has_nothrow_copy.qbk @@ -19,16 +19,11 @@ must be a complete type. These two traits are synonyms for each other. -__compat If the compiler does not support partial-specialization of class -templates, then this template can not be used with function types. - -Without some (as yet unspecified) help from the compiler, -`has_nothrow_copy` will never report that a class or struct has a -non-throwing copy-constructor; this is always safe, if possibly sub-optimal. -Currently (May 2011) compilers more recent than Visual C++ 8, GCC-4.3, Greenhills 6.0, -Intel-11.0, and Codegear have the necessary compiler __intrinsics to ensure that this -trait "just works". You may also test to see if the necessary __intrinsics are available -by checking to see if the macro `BOOST_HAS_NOTHROW_COPY` is defined. +__compat Either requires C++11 `noexcept` and `decltype` or else some (unspecified) help from the compiler. +Currently (June 2015) compilers more recent than Visual C++ 8, GCC-4.3, Greenhills 6.0, +Intel-11.0, and Codegear and all recent GCC versions have the necessary compiler __intrinsics to ensure that this +trait "just works". You may test to see if the necessary support is available +by checking to see if `defined(BOOST_HAS_NOTHROW_COPY) || (!defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_NOEXCEPT))` is true. __header ` #include ` or ` #include ` diff --git a/include/boost/type_traits/has_nothrow_copy.hpp b/include/boost/type_traits/has_nothrow_copy.hpp index bbfcb1d..1d4ae0e 100644 --- a/include/boost/type_traits/has_nothrow_copy.hpp +++ b/include/boost/type_traits/has_nothrow_copy.hpp @@ -16,18 +16,41 @@ #if defined(BOOST_CLANG) || defined(__GNUC__) || defined(__ghs__) || defined(__CODEGEARC__) #include +#include #include #ifdef BOOST_INTEL #include #endif #elif defined(BOOST_MSVC) || defined(BOOST_INTEL) #include +#include #endif namespace boost { template struct has_nothrow_copy_constructor : public integral_constant{}; +#elif !defined(BOOST_NO_CXX11_NOEXCEPT) + +#include +#include + +namespace boost{ + +namespace detail{ + +template +struct has_nothrow_copy_constructor_imp : public boost::integral_constant{}; +template +struct has_nothrow_copy_constructor_imp : public boost::integral_constant()))>{}; + +} + +template struct has_nothrow_copy_constructor : public detail::has_nothrow_copy_constructor_imp::value>{}; +template struct has_nothrow_copy_constructor : public integral_constant{}; +template struct has_nothrow_copy_constructor : public integral_constant{}; +template struct has_nothrow_copy_constructor : public integral_constant{}; + #else #include diff --git a/include/boost/type_traits/has_trivial_copy.hpp b/include/boost/type_traits/has_trivial_copy.hpp index 95bf159..c717f1d 100644 --- a/include/boost/type_traits/has_trivial_copy.hpp +++ b/include/boost/type_traits/has_trivial_copy.hpp @@ -10,35 +10,25 @@ #define BOOST_TT_HAS_TRIVIAL_COPY_HPP_INCLUDED #include -#include #include #include - -#ifdef __clang__ #include -#endif namespace boost { template struct has_trivial_copy : public integral_constant::value -# else - BOOST_HAS_TRIVIAL_COPY(T) -# endif #else - ::boost::is_pod::value && ! ::boost::is_volatile::value + ::boost::is_pod::value #endif >{}; - -#ifdef __clang__ - -template -struct has_trivial_copy : public has_trivial_copy{}; - -#endif +// Arrays are not explicitly copyable: +template struct has_trivial_copy : public false_type{}; +template struct has_trivial_copy : public false_type{}; +// Are volatile types ever trivial? We don't really know, so assume not: +template struct has_trivial_copy : public false_type{}; template <> struct has_trivial_copy : public false_type{}; #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS diff --git a/test/has_nothrow_copy_test.cpp b/test/has_nothrow_copy_test.cpp index befbb1d..a389abd 100644 --- a/test/has_nothrow_copy_test.cpp +++ b/test/has_nothrow_copy_test.cpp @@ -212,9 +212,10 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); #endif BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); -BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, true); -BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, true); -BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, true); +// These used to be true, but are now false to match std conforming behavior: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); // cases we would like to succeed but can't implement in the language: @@ -236,8 +237,10 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false) BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, true); #endif +#if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_nothrow_copy::value, false); - +#endif + TT_TEST_END diff --git a/test/has_trivial_copy_test.cpp b/test/has_trivial_copy_test.cpp index 9a0a042..6a803b8 100644 --- a/test/has_trivial_copy_test.cpp +++ b/test/has_trivial_copy_test.cpp @@ -194,9 +194,10 @@ BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, false); #endif BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, false); -BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, true); -BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, true); -BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, true); +// Arrays can not be explicitly copied: +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, false); +BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, false); BOOST_CHECK_INTEGRAL_CONSTANT(::tt::has_trivial_copy::value, false); // cases we would like to succeed but can't implement in the language: