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_base_of
125a83710eSEric Fiselier 
135a83710eSEric Fiselier #include <type_traits>
145a83710eSEric Fiselier 
15e12a536dSMarshall Clow #include "test_macros.h"
16e12a536dSMarshall Clow 
175a83710eSEric Fiselier template <class T, class U>
test_is_base_of()185a83710eSEric Fiselier void test_is_base_of()
195a83710eSEric Fiselier {
205a83710eSEric Fiselier     static_assert((std::is_base_of<T, U>::value), "");
215a83710eSEric Fiselier     static_assert((std::is_base_of<const T, U>::value), "");
225a83710eSEric Fiselier     static_assert((std::is_base_of<T, const U>::value), "");
235a83710eSEric Fiselier     static_assert((std::is_base_of<const T, const U>::value), "");
24803a8bb1SMarshall Clow #if TEST_STD_VER > 14
25e12a536dSMarshall Clow     static_assert((std::is_base_of_v<T, U>), "");
26e12a536dSMarshall Clow     static_assert((std::is_base_of_v<const T, U>), "");
27e12a536dSMarshall Clow     static_assert((std::is_base_of_v<T, const U>), "");
28e12a536dSMarshall Clow     static_assert((std::is_base_of_v<const T, const U>), "");
29e12a536dSMarshall Clow #endif
305a83710eSEric Fiselier }
315a83710eSEric Fiselier 
325a83710eSEric Fiselier template <class T, class U>
test_is_not_base_of()335a83710eSEric Fiselier void test_is_not_base_of()
345a83710eSEric Fiselier {
355a83710eSEric Fiselier     static_assert((!std::is_base_of<T, U>::value), "");
365a83710eSEric Fiselier }
375a83710eSEric Fiselier 
385a83710eSEric Fiselier struct B {};
395a83710eSEric Fiselier struct B1 : B {};
405a83710eSEric Fiselier struct B2 : B {};
415a83710eSEric Fiselier struct D : private B1, private B2 {};
42*402ca78cSMarshall Clow struct I0; // incomplete
435a83710eSEric Fiselier 
main(int,char **)442df59c50SJF Bastien int main(int, char**)
455a83710eSEric Fiselier {
465a83710eSEric Fiselier     test_is_base_of<B, D>();
475a83710eSEric Fiselier     test_is_base_of<B1, D>();
485a83710eSEric Fiselier     test_is_base_of<B2, D>();
495a83710eSEric Fiselier     test_is_base_of<B, B1>();
505a83710eSEric Fiselier     test_is_base_of<B, B2>();
515a83710eSEric Fiselier     test_is_base_of<B, B>();
525a83710eSEric Fiselier 
535a83710eSEric Fiselier     test_is_not_base_of<D, B>();
545a83710eSEric Fiselier     test_is_not_base_of<B&, D&>();
555a83710eSEric Fiselier     test_is_not_base_of<B[3], D[3]>();
565a83710eSEric Fiselier     test_is_not_base_of<int, int>();
572df59c50SJF Bastien 
58*402ca78cSMarshall Clow //  A scalar is never the base class of anything (including incomplete types)
59*402ca78cSMarshall Clow     test_is_not_base_of<int, B>();
60*402ca78cSMarshall Clow     test_is_not_base_of<int, B1>();
61*402ca78cSMarshall Clow     test_is_not_base_of<int, B2>();
62*402ca78cSMarshall Clow     test_is_not_base_of<int, D>();
63*402ca78cSMarshall Clow     test_is_not_base_of<int, I0>();
64*402ca78cSMarshall Clow 
65*402ca78cSMarshall Clow //  A scalar never has base classes (including incomplete types)
66*402ca78cSMarshall Clow     test_is_not_base_of<B,  int>();
67*402ca78cSMarshall Clow     test_is_not_base_of<B1, int>();
68*402ca78cSMarshall Clow     test_is_not_base_of<B2, int>();
69*402ca78cSMarshall Clow     test_is_not_base_of<D,  int>();
70*402ca78cSMarshall Clow     test_is_not_base_of<I0, int>();
71*402ca78cSMarshall Clow 
722df59c50SJF Bastien   return 0;
735a83710eSEric Fiselier }
74