From 9f29d67aaec18d09ec6c7f27ad6432f6fc9fa460 Mon Sep 17 00:00:00 2001 From: Phil Willoughby Date: Thu, 9 Nov 2017 11:39:48 -0800 Subject: [PATCH] Make ColdClassTest work on ancient compilers Summary: Some older versions of GCC/glibc/etc do not have the std::is_trivially*_constructible or std::is_trivially*_assignable traits. Reviewed By: yfeldblum Differential Revision: D6285887 fbshipit-source-id: 1eb4ae4f899dc1f528321f9f087390291687aca3 --- folly/lang/test/ColdClassTest.cpp | 35 ++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/folly/lang/test/ColdClassTest.cpp b/folly/lang/test/ColdClassTest.cpp index 30d70ce9..082db12f 100644 --- a/folly/lang/test/ColdClassTest.cpp +++ b/folly/lang/test/ColdClassTest.cpp @@ -21,23 +21,38 @@ using folly::ColdClass; -TEST(ColdClass, inheritance) { +template +static void validateInheritedClass() { // The only verifiable property of ColdClass is that it must not disrupt the // default constructor/destructor, default copy/move constructors and default // copy/move assignment operators when a class derives from it. - struct TestStruct : ColdClass {}; - EXPECT_TRUE(std::is_nothrow_default_constructible::value); - EXPECT_TRUE(std::is_trivially_copy_constructible::value); - EXPECT_TRUE(std::is_trivially_move_constructible::value); - EXPECT_TRUE(std::is_trivially_copy_assignable::value); - EXPECT_TRUE(std::is_trivially_move_assignable::value); - EXPECT_TRUE(std::is_trivially_destructible::value); - // Same again, but private inheritance. Should make no difference. - class TestClass : ColdClass {}; EXPECT_TRUE(std::is_nothrow_default_constructible::value); +#if !defined(__GLIBCXX__) || __GNUC__ >= 5 EXPECT_TRUE(std::is_trivially_copy_constructible::value); EXPECT_TRUE(std::is_trivially_move_constructible::value); EXPECT_TRUE(std::is_trivially_copy_assignable::value); EXPECT_TRUE(std::is_trivially_move_assignable::value); +#endif + EXPECT_TRUE(std::is_nothrow_copy_constructible::value); + EXPECT_TRUE(std::is_nothrow_move_constructible::value); + EXPECT_TRUE(std::is_nothrow_copy_assignable::value); + EXPECT_TRUE(std::is_nothrow_move_assignable::value); EXPECT_TRUE(std::is_trivially_destructible::value); } + +TEST(ColdClassTest, publicInheritance) { + struct TestPublic : ColdClass {}; + validateInheritedClass(); +} + +TEST(ColdClassTest, protectedInheritance) { + // Same again, but protected inheritance. Should make no difference. + class TestProtected : protected ColdClass {}; + validateInheritedClass(); +} + +TEST(ColdClassTest, privateInheritance) { + // Same again, but private inheritance. Should make no difference. + class TestPrivate : ColdClass {}; + validateInheritedClass(); +} -- 2.34.1