2 * Copyright 2004-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/lang/ColdClass.h>
19 #include <folly/portability/GTest.h>
20 #include <type_traits>
22 using folly::ColdClass;
24 TEST(ColdClass, inheritance) {
25 // The only verifiable property of ColdClass is that it must not disrupt the
26 // default constructor/destructor, default copy/move constructors and default
27 // copy/move assignment operators when a class derives from it.
28 struct TestStruct : ColdClass {};
29 EXPECT_TRUE(std::is_nothrow_default_constructible<TestStruct>::value);
30 EXPECT_TRUE(std::is_trivially_copy_constructible<TestStruct>::value);
31 EXPECT_TRUE(std::is_trivially_move_constructible<TestStruct>::value);
32 EXPECT_TRUE(std::is_trivially_copy_assignable<TestStruct>::value);
33 EXPECT_TRUE(std::is_trivially_move_assignable<TestStruct>::value);
34 EXPECT_TRUE(std::is_trivially_destructible<TestStruct>::value);
35 // Same again, but private inheritance. Should make no difference.
36 class TestClass : ColdClass {};
37 EXPECT_TRUE(std::is_nothrow_default_constructible<TestClass>::value);
38 EXPECT_TRUE(std::is_trivially_copy_constructible<TestClass>::value);
39 EXPECT_TRUE(std::is_trivially_move_constructible<TestClass>::value);
40 EXPECT_TRUE(std::is_trivially_copy_assignable<TestClass>::value);
41 EXPECT_TRUE(std::is_trivially_move_assignable<TestClass>::value);
42 EXPECT_TRUE(std::is_trivially_destructible<TestClass>::value);