xref: /llvm-project/libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_empty.pass.cpp (revision 2df59c50688c122bbcae7467d3eaf862c3ea3088)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier 
95a83710eSEric Fiselier // type_traits
105a83710eSEric Fiselier 
115a83710eSEric Fiselier // is_empty
125a83710eSEric Fiselier 
13d836a9d5SMarshall Clow // T is a non-union class type with:
14d836a9d5SMarshall Clow //  no non-static data members,
15d836a9d5SMarshall Clow //  no unnamed bit-fields of non-zero length,
16d836a9d5SMarshall Clow //  no virtual member functions,
17d836a9d5SMarshall Clow //  no virtual base classes,
18d836a9d5SMarshall Clow //  and no base class B for which is_empty_v<B> is false.
19d836a9d5SMarshall Clow 
20d836a9d5SMarshall Clow 
215a83710eSEric Fiselier #include <type_traits>
22d17405feSMarshall Clow #include "test_macros.h"
235a83710eSEric Fiselier 
245a83710eSEric Fiselier template <class T>
test_is_empty()255a83710eSEric Fiselier void test_is_empty()
265a83710eSEric Fiselier {
275a83710eSEric Fiselier     static_assert( std::is_empty<T>::value, "");
285a83710eSEric Fiselier     static_assert( std::is_empty<const T>::value, "");
295a83710eSEric Fiselier     static_assert( std::is_empty<volatile T>::value, "");
305a83710eSEric Fiselier     static_assert( std::is_empty<const volatile T>::value, "");
31dd0ef099SMarshall Clow #if TEST_STD_VER > 14
32dd0ef099SMarshall Clow     static_assert( std::is_empty_v<T>, "");
33dd0ef099SMarshall Clow     static_assert( std::is_empty_v<const T>, "");
34dd0ef099SMarshall Clow     static_assert( std::is_empty_v<volatile T>, "");
35dd0ef099SMarshall Clow     static_assert( std::is_empty_v<const volatile T>, "");
36dd0ef099SMarshall Clow #endif
375a83710eSEric Fiselier }
385a83710eSEric Fiselier 
395a83710eSEric Fiselier template <class T>
test_is_not_empty()405a83710eSEric Fiselier void test_is_not_empty()
415a83710eSEric Fiselier {
425a83710eSEric Fiselier     static_assert(!std::is_empty<T>::value, "");
435a83710eSEric Fiselier     static_assert(!std::is_empty<const T>::value, "");
445a83710eSEric Fiselier     static_assert(!std::is_empty<volatile T>::value, "");
455a83710eSEric Fiselier     static_assert(!std::is_empty<const volatile T>::value, "");
46dd0ef099SMarshall Clow #if TEST_STD_VER > 14
47dd0ef099SMarshall Clow     static_assert(!std::is_empty_v<T>, "");
48dd0ef099SMarshall Clow     static_assert(!std::is_empty_v<const T>, "");
49dd0ef099SMarshall Clow     static_assert(!std::is_empty_v<volatile T>, "");
50dd0ef099SMarshall Clow     static_assert(!std::is_empty_v<const volatile T>, "");
51dd0ef099SMarshall Clow #endif
525a83710eSEric Fiselier }
535a83710eSEric Fiselier 
54d836a9d5SMarshall Clow class Empty {};
55d836a9d5SMarshall Clow struct NotEmpty { int foo; };
565a83710eSEric Fiselier 
57d836a9d5SMarshall Clow class VirtualFn
585a83710eSEric Fiselier {
59d836a9d5SMarshall Clow     virtual ~VirtualFn();
605a83710eSEric Fiselier };
615a83710eSEric Fiselier 
625a83710eSEric Fiselier union Union {};
635a83710eSEric Fiselier 
64d836a9d5SMarshall Clow struct EmptyBase    : public Empty {};
65d836a9d5SMarshall Clow struct VirtualBase  : virtual Empty {};
66d836a9d5SMarshall Clow struct NotEmptyBase : public NotEmpty {};
67d836a9d5SMarshall Clow 
68d836a9d5SMarshall Clow struct StaticMember    { static int foo; };
69d836a9d5SMarshall Clow struct NonStaticMember {        int foo; };
70d836a9d5SMarshall Clow 
715a83710eSEric Fiselier struct bit_zero
725a83710eSEric Fiselier {
735a83710eSEric Fiselier     int :  0;
745a83710eSEric Fiselier };
755a83710eSEric Fiselier 
76d836a9d5SMarshall Clow struct bit_one
77d836a9d5SMarshall Clow {
78d836a9d5SMarshall Clow     int :  1;
79d836a9d5SMarshall Clow };
80d836a9d5SMarshall Clow 
main(int,char **)81*2df59c50SJF Bastien int main(int, char**)
825a83710eSEric Fiselier {
835a83710eSEric Fiselier     test_is_not_empty<void>();
845a83710eSEric Fiselier     test_is_not_empty<int&>();
855a83710eSEric Fiselier     test_is_not_empty<int>();
865a83710eSEric Fiselier     test_is_not_empty<double>();
875a83710eSEric Fiselier     test_is_not_empty<int*>();
885a83710eSEric Fiselier     test_is_not_empty<const int*>();
895a83710eSEric Fiselier     test_is_not_empty<char[3]>();
905a83710eSEric Fiselier     test_is_not_empty<char[]>();
915a83710eSEric Fiselier     test_is_not_empty<Union>();
925a83710eSEric Fiselier     test_is_not_empty<NotEmpty>();
93d836a9d5SMarshall Clow     test_is_not_empty<VirtualFn>();
94d836a9d5SMarshall Clow     test_is_not_empty<VirtualBase>();
95d836a9d5SMarshall Clow     test_is_not_empty<NotEmptyBase>();
96d836a9d5SMarshall Clow     test_is_not_empty<NonStaticMember>();
9723c725ebSMarshall Clow //    test_is_not_empty<bit_one>();
985a83710eSEric Fiselier 
995a83710eSEric Fiselier     test_is_empty<Empty>();
100d836a9d5SMarshall Clow     test_is_empty<EmptyBase>();
101d836a9d5SMarshall Clow     test_is_empty<StaticMember>();
1025a83710eSEric Fiselier     test_is_empty<bit_zero>();
103*2df59c50SJF Bastien 
104*2df59c50SJF Bastien   return 0;
1055a83710eSEric Fiselier }
106