xref: /llvm-project/libcxx/test/std/utilities/meta/meta.rel/is_base_of_union.pass.cpp (revision 5425106e493e26f7e0a87077c8eca657a9aff293)
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_base_of
12 
13 #include <type_traits>
14 
15 #include "test_macros.h"
16 
17 template <class T, class U>
test_is_base_of()18 void test_is_base_of()
19 {
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
30 }
31 
32 template <class T, class U>
test_is_not_base_of()33 void test_is_not_base_of()
34 {
35     static_assert((!std::is_base_of<T, U>::value), "");
36 }
37 
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 {};
46 
main(int,char **)47 int main(int, char**)
48 {
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>();
65 
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>();
82 
83   return 0;
84 }
85