]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr2/direct_bases/value.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr2 / direct_bases / value.cc
1 // { dg-do run { target c++11 } }
2 // { dg-require-effective-target rtti }
3 //
4 // Copyright (C) 2011-2023 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 #include <tr2/type_traits>
22 #include <typeinfo>
23 #include <stdexcept>
24
25 struct A { };
26 struct B1 : virtual public A { };
27 struct B2 : virtual public A { };
28 struct C : public B1, public B2 { };
29
30 void test()
31 {
32 // 1
33 {
34 typedef std::tr2::direct_bases<A>::type tl;
35 static_assert(tl::empty::value, "error");
36 }
37
38 // 2
39 {
40 typedef std::tr2::direct_bases<B1>::type tl1;
41 typedef std::tr2::direct_bases<B2>::type tl2;
42
43 // Sanity check w/ runtime.
44 bool eq = typeid(tl1) == typeid(tl2);
45 if (!eq)
46 throw std::logic_error("typelist not equal");
47
48 // Sanity check.
49 static_assert(tl1::empty::value != std::true_type::value, "!empty");
50 static_assert(tl2::empty::value != std::true_type::value, "!empty");
51
52 typedef tl1::first::type tl1_first;
53 typedef tl1::rest::type tl1_rest;
54 typedef tl2::first::type tl2_first;
55 typedef tl2::rest::type tl2_rest;
56
57 eq = typeid(tl1_first) == typeid(tl2_first);
58 if (!eq)
59 throw std::logic_error("base not equal");
60
61 static_assert(tl1_rest::empty::value == std::true_type::value, "empty");
62 static_assert(tl2_rest::empty::value == std::true_type::value, "empty");
63 }
64
65 // 3
66 {
67 typedef std::tr2::direct_bases<C>::type tl;
68
69 // Sanity check.
70 static_assert(tl::empty::value != std::true_type::value, "!empty");
71
72 typedef tl::first::type tl1_first;
73 typedef tl::rest::type tl2;
74 typedef tl2::first::type tl2_first;
75 typedef tl2::rest::type tl3;
76
77 bool eq = typeid(tl1_first) == typeid(tl2_first);
78 if (eq)
79 throw std::logic_error("bases are not equal");
80
81 static_assert(tl3::empty::value == std::true_type::value, "empty");
82 }
83
84 }
85
86 int main()
87 {
88 test();
89 return 0;
90 }