summaryrefslogtreecommitdiff
path: root/absl/meta/type_traits_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/meta/type_traits_test.cc')
-rw-r--r--absl/meta/type_traits_test.cc43
1 files changed, 22 insertions, 21 deletions
diff --git a/absl/meta/type_traits_test.cc b/absl/meta/type_traits_test.cc
index a7a9c5c9..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<DeletedDefaultCtor>::value);
-#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
// types with nontrivial destructor are nontrivial
EXPECT_FALSE(
absl::is_trivially_default_constructible<NontrivialDestructor>::value);
-#endif
// types with vtables
EXPECT_FALSE(absl::is_trivially_default_constructible<Base>::value);
@@ -546,6 +529,28 @@ TEST(TypeTraitsTest, TestTrivialDefaultCtor) {
#endif
}
+// GCC prior to 7.4 had a bug in its trivially-constructible traits
+// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80654).
+// This test makes sure that we do not depend on the trait in these cases when
+// implementing absl triviality traits.
+
+template <class T>
+struct BadConstructors {
+ BadConstructors() { static_assert(T::value, ""); }
+
+ BadConstructors(BadConstructors&&) { static_assert(T::value, ""); }
+
+ BadConstructors(const BadConstructors&) { static_assert(T::value, ""); }
+};
+
+TEST(TypeTraitsTest, TestTrivialityBadConstructors) {
+ using BadType = BadConstructors<int>;
+
+ EXPECT_FALSE(absl::is_trivially_default_constructible<BadType>::value);
+ EXPECT_FALSE(absl::is_trivially_move_constructible<BadType>::value);
+ EXPECT_FALSE(absl::is_trivially_copy_constructible<BadType>::value);
+}
+
TEST(TypeTraitsTest, TestTrivialMoveCtor) {
// Verify that arithmetic types and pointers have trivial move
// constructors.
@@ -585,11 +590,9 @@ TEST(TypeTraitsTest, TestTrivialMoveCtor) {
EXPECT_FALSE(
absl::is_trivially_move_constructible<NonCopyableOrMovable>::value);
-#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
// type with nontrivial destructor are nontrivial move construbtible
EXPECT_FALSE(
absl::is_trivially_move_constructible<NontrivialDestructor>::value);
-#endif
// types with vtables
EXPECT_FALSE(absl::is_trivially_move_constructible<Base>::value);
@@ -660,11 +663,9 @@ TEST(TypeTraitsTest, TestTrivialCopyCtor) {
EXPECT_FALSE(
absl::is_trivially_copy_constructible<NonCopyableOrMovable>::value);
-#ifdef ABSL_TRIVIALLY_CONSTRUCTIBLE_VERIFY_TRIVIALLY_DESTRUCTIBLE
// type with nontrivial destructor are nontrivial copy construbtible
EXPECT_FALSE(
absl::is_trivially_copy_constructible<NontrivialDestructor>::value);
-#endif
// types with vtables
EXPECT_FALSE(absl::is_trivially_copy_constructible<Base>::value);