[memprof] Move YAML traits to MemProf.h (NFC) (#118668)
[llvm-project.git] / libcxx / test / std / utilities / meta / meta.rel / is_base_of_union.pass.cpp
blob43f2bf723ad6ccbdd64ed5a5f016a7a6c7d645e3
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 //===----------------------------------------------------------------------===//
9 // type_traits
11 // is_base_of
13 #include <type_traits>
15 #include "test_macros.h"
17 template <class T, class U>
18 void test_is_base_of()
20 static_assert((std::is_base_of<T, U>::value), "");
21 static_assert((std::is_base_of<const T, U>::value), "");
22 static_assert((std::is_base_of<T, const U>::value), "");
23 static_assert((std::is_base_of<const T, const U>::value), "");
24 #if TEST_STD_VER > 14
25 static_assert((std::is_base_of_v<T, U>), "");
26 static_assert((std::is_base_of_v<const T, U>), "");
27 static_assert((std::is_base_of_v<T, const U>), "");
28 static_assert((std::is_base_of_v<const T, const U>), "");
29 #endif
32 template <class T, class U>
33 void test_is_not_base_of()
35 static_assert((!std::is_base_of<T, U>::value), "");
38 struct B {};
39 struct B1 : B {};
40 struct B2 : B {};
41 struct D : private B1, private B2 {};
42 union U0;
43 union U1 {};
44 struct I0;
45 struct I1 {};
47 int main(int, char**)
49 // A union is never the base class of anything (including incomplete types)
50 test_is_not_base_of<U0, B>();
51 test_is_not_base_of<U0, B1>();
52 test_is_not_base_of<U0, B2>();
53 test_is_not_base_of<U0, D>();
54 test_is_not_base_of<U1, B>();
55 test_is_not_base_of<U1, B1>();
56 test_is_not_base_of<U1, B2>();
57 test_is_not_base_of<U1, D>();
58 test_is_not_base_of<U0, I0>();
59 test_is_not_base_of<U1, I1>();
60 test_is_not_base_of<U0, U1>();
61 test_is_not_base_of<U0, int>();
62 test_is_not_base_of<U1, int>();
63 test_is_not_base_of<I0, int>();
64 test_is_not_base_of<I1, int>();
66 // A union never has base classes (including incomplete types)
67 test_is_not_base_of<B, U0>();
68 test_is_not_base_of<B1, U0>();
69 test_is_not_base_of<B2, U0>();
70 test_is_not_base_of<D, U0>();
71 test_is_not_base_of<B, U1>();
72 test_is_not_base_of<B1, U1>();
73 test_is_not_base_of<B2, U1>();
74 test_is_not_base_of<D, U1>();
75 test_is_not_base_of<I0, U0>();
76 test_is_not_base_of<I1, U1>();
77 test_is_not_base_of<U1, U0>();
78 test_is_not_base_of<int, U0>();
79 test_is_not_base_of<int, U1>();
80 test_is_not_base_of<int, I0>();
81 test_is_not_base_of<int, I1>();
83 return 0;