| 1 | // { dg-do run { target c++11 } } |
| 2 | // { dg-require-effective-target rtti } |
| 3 | // |
| 4 | // Copyright (C) 2011-2025 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::bases<A>::type tl; |
| 35 | static_assert(tl::empty::value, "error"); |
| 36 | } |
| 37 | |
| 38 | // 2 |
| 39 | { |
| 40 | typedef std::tr2::bases<B1>::type tl1; |
| 41 | typedef std::tr2::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::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 | typedef tl3::first::type tl3_first; |
| 77 | typedef tl3::rest::type tl4; |
| 78 | |
| 79 | bool eq = typeid(tl1_first) == typeid(tl2_first); |
| 80 | if (eq) |
| 81 | throw std::logic_error("bases are not equal"); |
| 82 | |
| 83 | eq = typeid(tl2_first) == typeid(tl3_first); |
| 84 | if (eq) |
| 85 | throw std::logic_error("bases are not equal"); |
| 86 | |
| 87 | static_assert(tl4::empty::value == std::true_type::value, "empty"); |
| 88 | } |
| 89 | |
| 90 | } |
| 91 | |
| 92 | int main() |
| 93 | { |
| 94 | test(); |
| 95 | return 0; |
| 96 | } |