1// { dg-options "-std=gnu++11" } 2// 3// Copyright (C) 2011-2015 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 24struct A { }; 25struct B1 : virtual public A { }; 26struct B2 : virtual public A { }; 27struct C : public B1, public B2 { }; 28 29void test() 30{ 31 bool test __attribute__((unused)) = true; 32 33 // 1 34 { 35 typedef std::tr2::direct_bases<A>::type tl; 36 static_assert(tl::empty::value, "error"); 37 } 38 39 // 2 40 { 41 typedef std::tr2::direct_bases<B1>::type tl1; 42 typedef std::tr2::direct_bases<B2>::type tl2; 43 44 // Sanity check w/ runtime. 45 bool eq = typeid(tl1) == typeid(tl2); 46 if (!eq) 47 throw std::logic_error("typelist not equal"); 48 49 // Sanity check. 50 static_assert(tl1::empty::value != std::true_type::value, "!empty"); 51 static_assert(tl2::empty::value != std::true_type::value, "!empty"); 52 53 typedef tl1::first::type tl1_first; 54 typedef tl1::rest::type tl1_rest; 55 typedef tl2::first::type tl2_first; 56 typedef tl2::rest::type tl2_rest; 57 58 eq = typeid(tl1_first) == typeid(tl2_first); 59 if (!eq) 60 throw std::logic_error("base not equal"); 61 62 static_assert(tl1_rest::empty::value == std::true_type::value, "empty"); 63 static_assert(tl2_rest::empty::value == std::true_type::value, "empty"); 64 } 65 66 // 3 67 { 68 typedef std::tr2::direct_bases<C>::type tl; 69 70 // Sanity check. 71 static_assert(tl::empty::value != std::true_type::value, "!empty"); 72 73 typedef tl::first::type tl1_first; 74 typedef tl::rest::type tl2; 75 typedef tl2::first::type tl2_first; 76 typedef tl2::rest::type tl3; 77 78 bool eq = typeid(tl1_first) == typeid(tl2_first); 79 if (eq) 80 throw std::logic_error("bases are not equal"); 81 82 static_assert(tl3::empty::value == std::true_type::value, "empty"); 83 } 84 85} 86 87int main() 88{ 89 test(); 90 return 0; 91} 92