1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // type_traits
10 
11 // is_empty
12 
13 // T is a non-union class type with:
14 //  no non-static data members,
15 //  no unnamed bit-fields of non-zero length,
16 //  no virtual member functions,
17 //  no virtual base classes,
18 //  and no base class B for which is_empty_v<B> is false.
19 
20 
21 #include <type_traits>
22 #include "test_macros.h"
23 
24 template <class T>
test_is_empty()25 void test_is_empty()
26 {
27     static_assert( std::is_empty<T>::value, "");
28     static_assert( std::is_empty<const T>::value, "");
29     static_assert( std::is_empty<volatile T>::value, "");
30     static_assert( std::is_empty<const volatile T>::value, "");
31 #if TEST_STD_VER > 14
32     static_assert( std::is_empty_v<T>, "");
33     static_assert( std::is_empty_v<const T>, "");
34     static_assert( std::is_empty_v<volatile T>, "");
35     static_assert( std::is_empty_v<const volatile T>, "");
36 #endif
37 }
38 
39 template <class T>
test_is_not_empty()40 void test_is_not_empty()
41 {
42     static_assert(!std::is_empty<T>::value, "");
43     static_assert(!std::is_empty<const T>::value, "");
44     static_assert(!std::is_empty<volatile T>::value, "");
45     static_assert(!std::is_empty<const volatile T>::value, "");
46 #if TEST_STD_VER > 14
47     static_assert(!std::is_empty_v<T>, "");
48     static_assert(!std::is_empty_v<const T>, "");
49     static_assert(!std::is_empty_v<volatile T>, "");
50     static_assert(!std::is_empty_v<const volatile T>, "");
51 #endif
52 }
53 
54 class Empty {};
55 struct NotEmpty { int foo; };
56 
57 class VirtualFn
58 {
59     virtual ~VirtualFn();
60 };
61 
62 union Union {};
63 
64 struct EmptyBase    : public Empty {};
65 struct VirtualBase  : virtual Empty {};
66 struct NotEmptyBase : public NotEmpty {};
67 
68 struct StaticMember    { static int foo; };
69 struct NonStaticMember {        int foo; };
70 
71 struct bit_zero
72 {
73     int :  0;
74 };
75 
76 struct bit_one
77 {
78     int :  1;
79 };
80 
main(int,char **)81 int main(int, char**)
82 {
83     test_is_not_empty<void>();
84     test_is_not_empty<int&>();
85     test_is_not_empty<int>();
86     test_is_not_empty<double>();
87     test_is_not_empty<int*>();
88     test_is_not_empty<const int*>();
89     test_is_not_empty<char[3]>();
90     test_is_not_empty<char[]>();
91     test_is_not_empty<Union>();
92     test_is_not_empty<NotEmpty>();
93     test_is_not_empty<VirtualFn>();
94     test_is_not_empty<VirtualBase>();
95     test_is_not_empty<NotEmptyBase>();
96     test_is_not_empty<NonStaticMember>();
97 //    test_is_not_empty<bit_one>();
98 
99     test_is_empty<Empty>();
100     test_is_empty<EmptyBase>();
101     test_is_empty<StaticMember>();
102     test_is_empty<bit_zero>();
103 
104   return 0;
105 }
106