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