From d659fe54b35ab9b8e35c72e50a4b8814167d5a84 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 4 Dec 2019 14:13:43 -0800 Subject: Export of internal Abseil changes -- c385118b3ef0528d150bfe7aeeb63e77f9e463cd by Matt Calabrese : Internal-only Archetype generation for testing generic code with user-defined types of various properties. PiperOrigin-RevId: 283833099 -- 4ccf340d3b295aa5b796ee5c97128b61d38899ea by Derek Mauro : Fixes the flags parse_test. Windows doesn't like consecutive path separators. PiperOrigin-RevId: 283614649 -- 5df6d83acb1e49cd1da785cfaf7551f05149f3c9 by Andy Getzendanner : ABSL_INTERNAL_LOG: forward complete __FILE__ to internal_log_function; not just basename. PiperOrigin-RevId: 283406080 GitOrigin-RevId: c385118b3ef0528d150bfe7aeeb63e77f9e463cd Change-Id: Ib0782354691a73fc40185c3262cfd507085b3393 --- absl/meta/type_traits.h | 45 +++++++++++++++++++++++++++++++++++-------- absl/meta/type_traits_test.cc | 21 -------------------- 2 files changed, 37 insertions(+), 29 deletions(-) (limited to 'absl/meta') diff --git a/absl/meta/type_traits.h b/absl/meta/type_traits.h index d57a8792..8cd5f043 100644 --- a/absl/meta/type_traits.h +++ b/absl/meta/type_traits.h @@ -41,8 +41,18 @@ #include "absl/base/config.h" +// MSVC constructibility traits do not detect destructor properties and so our +// implementations should not use them as a source-of-truth. +#if defined(_MSC_VER) && !defined(__clang__) && !defined(__GNUC__) +#define ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION 1 +#endif + namespace absl { +// Defined and documented later on in this file. +template +struct is_trivially_destructible; + // Defined and documented later on in this file. template struct is_trivially_move_assignable; @@ -65,6 +75,20 @@ union SingleMemberUnion { #pragma warning(pop) #endif // defined(_MSC_VER) && !defined(__GNUC__) +template +struct IsTriviallyMoveConstructibleObject + : std::integral_constant< + bool, std::is_move_constructible< + type_traits_internal::SingleMemberUnion>::value && + absl::is_trivially_destructible::value> {}; + +template +struct IsTriviallyCopyConstructibleObject + : std::integral_constant< + bool, std::is_copy_constructible< + type_traits_internal::SingleMemberUnion>::value && + absl::is_trivially_destructible::value> {}; + template struct IsTriviallyMoveAssignableReference : std::false_type {}; @@ -323,7 +347,9 @@ struct is_trivially_default_constructible : std::integral_constant::value && is_trivially_destructible::value> { -#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE +#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ + !defined( \ + ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) private: static constexpr bool compliant = std::is_trivially_default_constructible::value == @@ -354,10 +380,11 @@ template struct is_trivially_move_constructible : std::conditional< std::is_object::value && !std::is_array::value, - std::is_move_constructible< - type_traits_internal::SingleMemberUnion>, + type_traits_internal::IsTriviallyMoveConstructibleObject, std::is_reference>::type::type { -#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE +#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ + !defined( \ + ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) private: static constexpr bool compliant = std::is_trivially_move_constructible::value == @@ -388,10 +415,11 @@ template struct is_trivially_copy_constructible : std::conditional< std::is_object::value && !std::is_array::value, - std::is_copy_constructible< - type_traits_internal::SingleMemberUnion>, + type_traits_internal::IsTriviallyCopyConstructibleObject, std::is_lvalue_reference>::type::type { -#ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE +#if defined(ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE) && \ + !defined( \ + ABSL_META_INTERNAL_STD_CONSTRUCTION_TRAITS_DONT_CHECK_DESTRUCTION) private: static constexpr bool compliant = std::is_trivially_copy_constructible::value == @@ -423,7 +451,8 @@ struct is_trivially_copy_constructible template struct is_trivially_move_assignable : std::conditional< - std::is_object::value && !std::is_array::value, + std::is_object::value && !std::is_array::value && + std::is_move_assignable::value, std::is_move_assignable>, type_traits_internal::IsTriviallyMoveAssignableReference>::type:: type { diff --git a/absl/meta/type_traits_test.cc b/absl/meta/type_traits_test.cc index 6fbb42f8..1aafd0d4 100644 --- a/absl/meta/type_traits_test.cc +++ b/absl/meta/type_traits_test.cc @@ -347,21 +347,6 @@ class Base { virtual ~Base() {} }; -// In GCC/Clang, std::is_trivially_constructible requires that the destructor is -// trivial. However, MSVC doesn't require that. This results in different -// behavior when checking is_trivially_constructible on any type with -// nontrivial destructor. Since absl::is_trivially_default_constructible and -// absl::is_trivially_copy_constructible both follows Clang/GCC's interpretation -// and check is_trivially_destructible, it results in inconsistency with -// std::is_trivially_xxx_constructible on MSVC. This macro is used to work -// around this issue in test. In practice, a trivially constructible type -// should also be trivially destructible. -// GCC bug 51452: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51452 -// LWG issue 2116: http://cplusplus.github.io/LWG/lwg-active.html#2116 -#ifndef _MSC_VER -#define ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE 1 -#endif - // Old versions of libc++, around Clang 3.5 to 3.6, consider deleted destructors // as also being trivial. With the resolution of CWG 1928 and CWG 1734, this // is no longer considered true and has thus been amended. @@ -499,11 +484,9 @@ TEST(TypeTraitsTest, TestTrivialDefaultCtor) { EXPECT_FALSE( absl::is_trivially_default_constructible::value); -#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE // types with nontrivial destructor are nontrivial EXPECT_FALSE( absl::is_trivially_default_constructible::value); -#endif // types with vtables EXPECT_FALSE(absl::is_trivially_default_constructible::value); @@ -607,11 +590,9 @@ TEST(TypeTraitsTest, TestTrivialMoveCtor) { EXPECT_FALSE( absl::is_trivially_move_constructible::value); -#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE // type with nontrivial destructor are nontrivial move construbtible EXPECT_FALSE( absl::is_trivially_move_constructible::value); -#endif // types with vtables EXPECT_FALSE(absl::is_trivially_move_constructible::value); @@ -682,11 +663,9 @@ TEST(TypeTraitsTest, TestTrivialCopyCtor) { EXPECT_FALSE( absl::is_trivially_copy_constructible::value); -#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE // type with nontrivial destructor are nontrivial copy construbtible EXPECT_FALSE( absl::is_trivially_copy_constructible::value); -#endif // types with vtables EXPECT_FALSE(absl::is_trivially_copy_constructible::value); -- cgit v1.2.3