From 4132ce25956a91e1224e0f205b7f8c326304a995 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Fri, 5 Jan 2018 07:54:33 -0800 Subject: Changes imported from Abseil "staging" branch: - 0a519d9a4507158267cc515e0c7c83959d94fc78 Fix missing header include when compiling with _GLIBCXX_D... by Alex Strelnikov - d089af70781d92af9a5de2d84c417ddf2c87689a Internal change by Gennadiy Rozental - 0d3afc89d3907923ede964d58c6bcca579e8ad65 Test absl::any for exception safety. This test is tempor... by Jon Cohen - 29af424b8a3174a7b3e657e478aa30a8a425aee2 Tweak the ABSL type trait library and expand its tests. by Abseil Team - 99ab42b2ebbe466cc3730fb6b16b5fad848f95af Rollback GLIBCXX_DEBUG fix due to internal breakage. by Alex Strelnikov - 1a5bcb93ee16d4dd2170254e54c4b62b38fbf17b Internal change. by Abseil Team - 46de7d09c7d4aef5b7b5389ce9b4f96b654aac02 absl::string_view::rfind: doc fix. by Abseil Team - edda4c7ddd2d76fbb5b3fd5226b95082083c57d9 Fix string_view_test with c++17/clang/libc++ to address by Xiaoyi Zhang GitOrigin-RevId: 0a519d9a4507158267cc515e0c7c83959d94fc78 Change-Id: Ie27de1be3e79bba011f05e924d34e8fcc62d8de5 --- absl/meta/type_traits.h | 66 ++++++--- absl/meta/type_traits_test.cc | 337 ++++++++++++++++++++++++++++++------------ 2 files changed, 289 insertions(+), 114 deletions(-) (limited to 'absl/meta') diff --git a/absl/meta/type_traits.h b/absl/meta/type_traits.h index 6f7138c2d8db..f36a59aa7777 100644 --- a/absl/meta/type_traits.h +++ b/absl/meta/type_traits.h @@ -148,11 +148,16 @@ struct negation : std::integral_constant {}; template struct is_trivially_destructible : std::integral_constant::value> { + std::is_destructible::value> { #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE - static_assert(std::is_trivially_destructible::value == - is_trivially_destructible::value, - "Not compliant with std::is_trivially_destructible"); + static constexpr bool compliant = std::is_trivially_destructible::value == + is_trivially_destructible::value; + static_assert(compliant || std::is_trivially_destructible::value, + "Not compliant with std::is_trivially_destructible; " + "Standard: false, Implementation: true"); + static_assert(compliant || !std::is_trivially_destructible::value, + "Not compliant with std::is_trivially_destructible; " + "Standard: true, Implementation: false"); #endif // ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE }; @@ -186,18 +191,23 @@ struct is_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. // -// "T obj();" need to be well-formed and not call any non-trivial operation. +// "T obj();" need to be well-formed and not call any nontrivial operation. // Nontrivally destructible types will cause the expression to be nontrivial. template struct is_trivially_default_constructible - : std::integral_constant::value && - is_trivially_destructible::value> { + : std::integral_constant::value && + is_trivially_destructible::value> { #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE - static_assert(std::is_trivially_default_constructible::value == - is_trivially_default_constructible::value, - "Not compliant with std::is_trivially_default_constructible"); + static constexpr bool compliant = + std::is_trivially_default_constructible::value == + is_trivially_default_constructible::value; + static_assert(compliant || std::is_trivially_default_constructible::value, + "Not compliant with std::is_trivially_default_constructible; " + "Standard: false, Implementation: true"); + static_assert(compliant || !std::is_trivially_default_constructible::value, + "Not compliant with std::is_trivially_default_constructible; " + "Standard: true, Implementation: false"); #endif // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE }; @@ -217,12 +227,18 @@ struct is_trivially_default_constructible template struct is_trivially_copy_constructible : std::integral_constant::value && - is_trivially_destructible::value> { + std::is_copy_constructible::value && + is_trivially_destructible::value> { #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE - static_assert(std::is_trivially_copy_constructible::value == - is_trivially_copy_constructible::value, - "Not compliant with std::is_trivially_copy_constructible"); + static constexpr bool compliant = + std::is_trivially_copy_constructible::value == + is_trivially_copy_constructible::value; + static_assert(compliant || std::is_trivially_copy_constructible::value, + "Not compliant with std::is_trivially_copy_constructible; " + "Standard: false, Implementation: true"); + static_assert(compliant || !std::is_trivially_copy_constructible::value, + "Not compliant with std::is_trivially_copy_constructible; " + "Standard: true, Implementation: false"); #endif // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE }; @@ -240,15 +256,21 @@ struct is_trivially_copy_constructible // `declval() = declval()` is well-formed when treated as an unevaluated // operand. `is_trivially_assignable` requires the assignment to call no // operation that is not trivial. `is_trivially_copy_assignable` is simply -// `is_trivially_assignable`. +// `is_trivially_assignable`. template struct is_trivially_copy_assignable : std::integral_constant::value> { + std::is_copy_assignable::value> { #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE - static_assert(std::is_trivially_copy_assignable::value == - is_trivially_copy_assignable::value, - "Not compliant with std::is_trivially_copy_assignable"); + static constexpr bool compliant = + std::is_trivially_copy_assignable::value == + is_trivially_copy_assignable::value; + static_assert(compliant || std::is_trivially_copy_assignable::value, + "Not compliant with std::is_trivially_copy_assignable; " + "Standard: false, Implementation: true"); + static_assert(compliant || !std::is_trivially_copy_assignable::value, + "Not compliant with std::is_trivially_copy_assignable; " + "Standard: true, Implementation: false"); #endif // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE }; diff --git a/absl/meta/type_traits_test.cc b/absl/meta/type_traits_test.cc index 67d1c4555c4a..c44d1c5ff850 100644 --- a/absl/meta/type_traits_test.cc +++ b/absl/meta/type_traits_test.cc @@ -99,6 +99,18 @@ class Trivial { int n_; }; +struct TrivialDestructor { + ~TrivialDestructor() = default; +}; + +struct NontrivialDestructor { + ~NontrivialDestructor() {} +}; + +struct DeletedDestructor { + ~DeletedDestructor() = delete; +}; + class TrivialDefaultCtor { public: TrivialDefaultCtor() = default; @@ -108,6 +120,23 @@ class TrivialDefaultCtor { int n_; }; +class NontrivialDefaultCtor { + public: + NontrivialDefaultCtor() : n_(1) {} + + private: + int n_; +}; + +class DeletedDefaultCtor { + public: + DeletedDefaultCtor() = delete; + explicit DeletedDefaultCtor(int n) : n_(n) {} + + private: + int n_; +}; + class TrivialCopyCtor { public: explicit TrivialCopyCtor(int n) : n_(n) {} @@ -121,22 +150,57 @@ class TrivialCopyCtor { int n_; }; +class NontrivialCopyCtor { + public: + explicit NontrivialCopyCtor(int n) : n_(n) {} + NontrivialCopyCtor(const NontrivialCopyCtor& t) : n_(t.n_) {} + NontrivialCopyCtor& operator=(const NontrivialCopyCtor&) = default; + + private: + int n_; +}; + +class DeletedCopyCtor { + public: + explicit DeletedCopyCtor(int n) : n_(n) {} + DeletedCopyCtor(const DeletedCopyCtor&) = delete; + DeletedCopyCtor& operator=(const DeletedCopyCtor&) = default; + + private: + int n_; +}; + class TrivialCopyAssign { public: explicit TrivialCopyAssign(int n) : n_(n) {} TrivialCopyAssign(const TrivialCopyAssign& t) : n_(t.n_) {} TrivialCopyAssign& operator=(const TrivialCopyAssign& t) = default; - ~TrivialCopyAssign() {} // can have non trivial destructor + ~TrivialCopyAssign() {} // can have nontrivial destructor private: int n_; }; -struct NonTrivialDestructor { - ~NonTrivialDestructor() {} +class NontrivialCopyAssign { + public: + explicit NontrivialCopyAssign(int n) : n_(n) {} + NontrivialCopyAssign(const NontrivialCopyAssign&) = default; + NontrivialCopyAssign& operator=(const NontrivialCopyAssign& t) { + n_ = t.n_; + return *this; + } + + private: + int n_; }; -struct TrivialDestructor { - ~TrivialDestructor() = default; +class DeletedCopyAssign { + public: + explicit DeletedCopyAssign(int n) : n_(n) {} + DeletedCopyAssign(const DeletedCopyAssign&) = default; + DeletedCopyAssign& operator=(const DeletedCopyAssign&) = delete; + + private: + int n_; }; struct NonCopyable { @@ -152,19 +216,105 @@ class 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 +// 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. -#ifdef _MSC_VER -#define ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE +// 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. +// Compiler Explorer: https://godbolt.org/g/zT59ZL +// CWG issue 1734: http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1734 +// CWG issue 1928: http://open-std.org/JTC1/SC22/WG21/docs/cwg_closed.html#1928 +#if !defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 3700 +#define ABSL_TRIVIALLY_DESTRUCTIBLE_CONSIDER_DELETED_DESTRUCTOR_NOT_TRIVIAL 1 +#endif + +// As of the moment, GCC versions >5.1 have a problem compiling for +// std::is_trivially_default_constructible, where +// NontrivialDestructor is a struct with a custom nontrivial destructor. Note +// that this problem only occurs for arrays of a known size, so something like +// std::is_trivially_default_constructible does not +// have any problems. +// Compiler Explorer: https://godbolt.org/g/dXRbdK +// GCC bug 83689: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83689 +#if defined(__clang__) || defined(_MSC_VER) || \ + (defined(__GNUC__) && __GNUC__ < 5) +#define ABSL_GCC_BUG_TRIVIALLY_CONSTRUCTIBLE_ON_ARRAY_OF_NONTRIVIAL 1 +#endif + +TEST(TypeTraitsTest, TestTrivialDestructor) { + // Verify that arithmetic types and pointers have trivial destructors. + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + + // classes with destructors + EXPECT_TRUE(absl::is_trivially_destructible::value); + EXPECT_TRUE(absl::is_trivially_destructible::value); + + // Verify that types with a nontrivial or deleted destructor + // are marked as such. + EXPECT_FALSE(absl::is_trivially_destructible::value); +#ifdef ABSL_TRIVIALLY_DESTRUCTIBLE_CONSIDER_DELETED_DESTRUCTOR_NOT_TRIVIAL + EXPECT_FALSE(absl::is_trivially_destructible::value); +#endif + + // simple_pair of such types is trivial + EXPECT_TRUE((absl::is_trivially_destructible>::value)); + EXPECT_TRUE((absl::is_trivially_destructible< + simple_pair>::value)); + + // Verify that types without trivial destructors are correctly marked as such. + EXPECT_FALSE(absl::is_trivially_destructible::value); + EXPECT_FALSE(absl::is_trivially_destructible>::value); + + // Verify that simple_pairs of types without trivial destructors + // are not marked as trivial. + EXPECT_FALSE((absl::is_trivially_destructible< + simple_pair>::value)); + EXPECT_FALSE((absl::is_trivially_destructible< + simple_pair>::value)); + + // array of such types is trivial + using int10 = int[10]; + EXPECT_TRUE(absl::is_trivially_destructible::value); + using Trivial10 = Trivial[10]; + EXPECT_TRUE(absl::is_trivially_destructible::value); + using TrivialDestructor10 = TrivialDestructor[10]; + EXPECT_TRUE(absl::is_trivially_destructible::value); + + // Conversely, the opposite also holds. + using NontrivialDestructor10 = NontrivialDestructor[10]; + EXPECT_FALSE(absl::is_trivially_destructible::value); +} + TEST(TypeTraitsTest, TestTrivialDefaultCtor) { // arithmetic types and pointers have trivial default constructors. EXPECT_TRUE(absl::is_trivially_default_constructible::value); @@ -184,42 +334,67 @@ TEST(TypeTraitsTest, TestTrivialDefaultCtor) { EXPECT_TRUE(absl::is_trivially_default_constructible::value); EXPECT_TRUE(absl::is_trivially_default_constructible::value); EXPECT_TRUE( - absl::is_trivially_default_constructible::value); - EXPECT_TRUE( - absl::is_trivially_default_constructible::value); + absl::is_trivially_default_constructible::value); + EXPECT_TRUE(absl::is_trivially_default_constructible::value); + EXPECT_TRUE(absl::is_trivially_default_constructible::value); + EXPECT_TRUE(absl::is_trivially_default_constructible::value); // types with compiler generated default ctors EXPECT_TRUE(absl::is_trivially_default_constructible::value); EXPECT_TRUE( absl::is_trivially_default_constructible::value); -#ifndef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE - // types with non trivial destructor are non trivial + // Verify that types without them are not. EXPECT_FALSE( - absl::is_trivially_default_constructible::value); + absl::is_trivially_default_constructible::value); + 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); - // Verify that arrays of such types are trivially default constructible - typedef int int10[10]; - EXPECT_TRUE(absl::is_trivially_default_constructible::value); - typedef Trivial Trivial10[10]; - EXPECT_TRUE(absl::is_trivially_default_constructible::value); - typedef Trivial TrivialDefaultCtor10[10]; - EXPECT_TRUE( - absl::is_trivially_default_constructible::value); - // Verify that simple_pair has trivial constructors where applicable. EXPECT_TRUE((absl::is_trivially_default_constructible< simple_pair>::value)); + EXPECT_TRUE((absl::is_trivially_default_constructible< + simple_pair>::value)); + EXPECT_TRUE((absl::is_trivially_default_constructible< + simple_pair>::value)); // Verify that types without trivial constructors are // correctly marked as such. EXPECT_FALSE(absl::is_trivially_default_constructible::value); EXPECT_FALSE( absl::is_trivially_default_constructible>::value); + + // Verify that simple_pairs of types without trivial constructors + // are not marked as trivial. + EXPECT_FALSE((absl::is_trivially_default_constructible< + simple_pair>::value)); + EXPECT_FALSE((absl::is_trivially_default_constructible< + simple_pair>::value)); + + // Verify that arrays of such types are trivially default constructible + using int10 = int[10]; + EXPECT_TRUE(absl::is_trivially_default_constructible::value); + using Trivial10 = Trivial[10]; + EXPECT_TRUE(absl::is_trivially_default_constructible::value); + using TrivialDefaultCtor10 = TrivialDefaultCtor[10]; + EXPECT_TRUE( + absl::is_trivially_default_constructible::value); + + // Conversely, the opposite also holds. +#ifdef ABSL_GCC_BUG_TRIVIALLY_CONSTRUCTIBLE_ON_ARRAY_OF_NONTRIVIAL + using NontrivialDefaultCtor10 = NontrivialDefaultCtor[10]; + EXPECT_FALSE( + absl::is_trivially_default_constructible::value); +#endif } TEST(TypeTraitsTest, TestTrivialCopyCtor) { @@ -241,18 +416,26 @@ TEST(TypeTraitsTest, TestTrivialCopyCtor) { EXPECT_TRUE(absl::is_trivially_copy_constructible::value); EXPECT_TRUE(absl::is_trivially_copy_constructible::value); EXPECT_TRUE(absl::is_trivially_copy_constructible::value); - EXPECT_TRUE( - absl::is_trivially_copy_constructible::value); - EXPECT_TRUE(absl::is_trivially_copy_constructible::value); + EXPECT_TRUE(absl::is_trivially_copy_constructible::value); + EXPECT_TRUE(absl::is_trivially_copy_constructible::value); + EXPECT_TRUE(absl::is_trivially_copy_constructible::value); + EXPECT_TRUE(absl::is_trivially_copy_constructible::value); // types with compiler generated copy ctors EXPECT_TRUE(absl::is_trivially_copy_constructible::value); EXPECT_TRUE(absl::is_trivially_copy_constructible::value); -#ifndef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE - // type with non-trivial destructor are non-trivial copy construbtible + // Verify that types without them (i.e. nontrivial or deleted) are not. + EXPECT_FALSE( + absl::is_trivially_copy_constructible::value); + EXPECT_FALSE(absl::is_trivially_copy_constructible::value); + 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); + absl::is_trivially_copy_constructible::value); #endif // types with vtables @@ -266,9 +449,10 @@ TEST(TypeTraitsTest, TestTrivialCopyCtor) { EXPECT_TRUE((absl::is_trivially_copy_constructible< simple_pair>::value)); - // Verify that arrays are not - typedef int int10[10]; - EXPECT_FALSE(absl::is_trivially_copy_constructible::value); + // Verify that types without trivial copy constructors are + // correctly marked as such. + EXPECT_FALSE(absl::is_trivially_copy_constructible::value); + EXPECT_FALSE(absl::is_trivially_copy_constructible>::value); // Verify that simple_pairs of types without trivial copy constructors // are not marked as trivial. @@ -277,18 +461,14 @@ TEST(TypeTraitsTest, TestTrivialCopyCtor) { EXPECT_FALSE((absl::is_trivially_copy_constructible< simple_pair>::value)); - // Verify that types without trivial copy constructors are - // correctly marked as such. - EXPECT_FALSE(absl::is_trivially_copy_constructible::value); - EXPECT_FALSE(absl::is_trivially_copy_constructible>::value); - - // types with deleted copy constructors are not copy constructible - EXPECT_FALSE(absl::is_trivially_copy_constructible::value); + // Verify that arrays are not + using int10 = int[10]; + EXPECT_FALSE(absl::is_trivially_copy_constructible::value); } TEST(TypeTraitsTest, TestTrivialCopyAssign) { // Verify that arithmetic types and pointers have trivial copy - // constructors. + // assignment operators. EXPECT_TRUE(absl::is_trivially_copy_assignable::value); EXPECT_TRUE(absl::is_trivially_copy_assignable::value); EXPECT_TRUE(absl::is_trivially_copy_assignable::value); @@ -305,9 +485,10 @@ TEST(TypeTraitsTest, TestTrivialCopyAssign) { EXPECT_TRUE(absl::is_trivially_copy_assignable::value); EXPECT_TRUE(absl::is_trivially_copy_assignable::value); EXPECT_TRUE(absl::is_trivially_copy_assignable::value); - EXPECT_TRUE( - absl::is_trivially_copy_assignable::value); - EXPECT_TRUE(absl::is_trivially_copy_assignable::value); + EXPECT_TRUE(absl::is_trivially_copy_assignable::value); + EXPECT_TRUE(absl::is_trivially_copy_assignable::value); + EXPECT_TRUE(absl::is_trivially_copy_assignable::value); + EXPECT_TRUE(absl::is_trivially_copy_assignable::value); // const qualified types are not assignable EXPECT_FALSE(absl::is_trivially_copy_assignable::value); @@ -316,65 +497,37 @@ TEST(TypeTraitsTest, TestTrivialCopyAssign) { EXPECT_TRUE(absl::is_trivially_copy_assignable::value); EXPECT_TRUE(absl::is_trivially_copy_assignable::value); + // Verify that types without them (i.e. nontrivial or deleted) are not. + EXPECT_FALSE(absl::is_trivially_copy_assignable::value); + EXPECT_FALSE(absl::is_trivially_copy_assignable::value); + EXPECT_FALSE(absl::is_trivially_copy_assignable::value); + // types with vtables EXPECT_FALSE(absl::is_trivially_copy_assignable::value); - // Verify that arrays are not trivially copy assignable - typedef int int10[10]; - EXPECT_FALSE(absl::is_trivially_copy_assignable::value); - // Verify that simple_pair is trivially assignable EXPECT_TRUE( (absl::is_trivially_copy_assignable>::value)); + EXPECT_TRUE( + (absl::is_trivially_copy_assignable>::value)); + EXPECT_TRUE((absl::is_trivially_copy_assignable< + simple_pair>::value)); - // Verify that types without trivial copy constructors are + // Verify that types not trivially copy assignable are // correctly marked as such. EXPECT_FALSE(absl::is_trivially_copy_assignable::value); EXPECT_FALSE(absl::is_trivially_copy_assignable>::value); - // types with deleted copy assignment are not copy assignable - EXPECT_FALSE(absl::is_trivially_copy_assignable::value); -} - -TEST(TypeTraitsTest, TestTrivialDestructor) { - // Verify that arithmetic types and pointers have trivial copy - // constructors. - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - - // classes with destructors - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_TRUE(absl::is_trivially_destructible::value); - EXPECT_FALSE(absl::is_trivially_destructible::value); - - // simple_pair of such types is trivial - EXPECT_TRUE((absl::is_trivially_destructible>::value)); - EXPECT_TRUE((absl::is_trivially_destructible< - simple_pair>::value)); + // Verify that simple_pairs of types not trivially copy assignable + // are not marked as trivial. + EXPECT_FALSE((absl::is_trivially_copy_assignable< + simple_pair>::value)); + EXPECT_FALSE((absl::is_trivially_copy_assignable< + simple_pair>::value)); - // array of such types is trivial - typedef int int10[10]; - EXPECT_TRUE(absl::is_trivially_destructible::value); - typedef TrivialDestructor TrivialDestructor10[10]; - EXPECT_TRUE(absl::is_trivially_destructible::value); - typedef NonTrivialDestructor NonTrivialDestructor10[10]; - EXPECT_FALSE(absl::is_trivially_destructible::value); + // Verify that arrays are not trivially copy assignable + using int10 = int[10]; + EXPECT_FALSE(absl::is_trivially_copy_assignable::value); } #define ABSL_INTERNAL_EXPECT_ALIAS_EQUIVALENCE(trait_name, ...) \ -- cgit 1.4.1