1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
), "");
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
>), "");
32 template <class T
, class U
>
33 void test_is_not_base_of()
35 static_assert((!std::is_base_of
<T
, U
>::value
), "");
41 struct D
: private B1
, private B2
{};
42 struct I0
; // incomplete
46 test_is_base_of
<B
, D
>();
47 test_is_base_of
<B1
, D
>();
48 test_is_base_of
<B2
, D
>();
49 test_is_base_of
<B
, B1
>();
50 test_is_base_of
<B
, B2
>();
51 test_is_base_of
<B
, B
>();
53 test_is_not_base_of
<D
, B
>();
54 test_is_not_base_of
<B
&, D
&>();
55 test_is_not_base_of
<B
[3], D
[3]>();
56 test_is_not_base_of
<int, int>();
58 // A scalar is never the base class of anything (including incomplete types)
59 test_is_not_base_of
<int, B
>();
60 test_is_not_base_of
<int, B1
>();
61 test_is_not_base_of
<int, B2
>();
62 test_is_not_base_of
<int, D
>();
63 test_is_not_base_of
<int, I0
>();
65 // A scalar never has base classes (including incomplete types)
66 test_is_not_base_of
<B
, int>();
67 test_is_not_base_of
<B1
, int>();
68 test_is_not_base_of
<B2
, int>();
69 test_is_not_base_of
<D
, int>();
70 test_is_not_base_of
<I0
, int>();