+2011-10-17 Michael Spertus <mike_spertus@symantec.com>
+
+ * gcc/c-family/c-common.c (c_common_reswords): Add __bases,
+ __direct_bases.
+ * gcc/c-family/c-common.h: Add RID_BASES and RID_DIRECT_BASES.
+
2011-10-17 Simon Baldwin <simonb@google.com>
Ian Lance Taylor <iant@google.com>
{ "__asm__", RID_ASM, 0 },
{ "__attribute", RID_ATTRIBUTE, 0 },
{ "__attribute__", RID_ATTRIBUTE, 0 },
+ { "__bases", RID_BASES, D_CXXONLY },
{ "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY },
{ "__builtin_complex", RID_BUILTIN_COMPLEX, D_CONLY },
{ "__builtin_shuffle", RID_BUILTIN_SHUFFLE, D_CONLY },
{ "__const", RID_CONST, 0 },
{ "__const__", RID_CONST, 0 },
{ "__decltype", RID_DECLTYPE, D_CXXONLY },
+ { "__direct_bases", RID_DIRECT_BASES, D_CXXONLY },
{ "__extension__", RID_EXTENSION, 0 },
{ "__func__", RID_C99_FUNCTION_NAME, 0 },
{ "__has_nothrow_assign", RID_HAS_NOTHROW_ASSIGN, D_CXXONLY },
RID_CONSTCAST, RID_DYNCAST, RID_REINTCAST, RID_STATCAST,
/* C++ extensions */
+ RID_BASES, RID_DIRECT_BASES,
RID_HAS_NOTHROW_ASSIGN, RID_HAS_NOTHROW_CONSTRUCTOR,
RID_HAS_NOTHROW_COPY, RID_HAS_TRIVIAL_ASSIGN,
RID_HAS_TRIVIAL_CONSTRUCTOR, RID_HAS_TRIVIAL_COPY,
RID_HAS_TRIVIAL_DESTRUCTOR, RID_HAS_VIRTUAL_DESTRUCTOR,
RID_IS_ABSTRACT, RID_IS_BASE_OF,
- RID_IS_CONVERTIBLE_TO, RID_IS_CLASS,
+ RID_IS_CLASS, RID_IS_CONVERTIBLE_TO,
RID_IS_EMPTY, RID_IS_ENUM,
RID_IS_LITERAL_TYPE, RID_IS_POD,
RID_IS_POLYMORPHIC, RID_IS_STD_LAYOUT,
+2011-10-17 Michael Spertus <mike_spertus@symantec.com>
+
+ * cp-tree.def: Add BASES as a new tree code.
+ * cp-tree.h (enum cp_trait_kind): Add CPTK_BASES, CPTK_DIRECT_BASES.
+ (BASES_TYPE, BASES_DIRECT): Define.
+ (calculate_bases, finish_bases, calculate_direct_bases): Declare.
+ * parser.c (cp_parser_trait_expr, cp_parser_template_argument_list,
+ (cp_parser_simple_type_specifier, cp_parser_save_nsdmi): Use them.
+ * pt.c (find_parameter_packs_r, tsubst_pack_expansion): Likewise.
+ * semantics.c (calculate_bases, finish_bases, calculate_direct_bases,
+ dfs_calculate_bases_pre, dfs_calculate_bases_post,
+ calculate_bases_helper): Define.
+
2011-10-17 Jason Merrill <jason@redhat.com>
PR c++/50736
UNDERLYING_TYPE_TYPE is the type in question. */
DEFTREECODE (UNDERLYING_TYPE, "underlying_type", tcc_type, 0)
+/* A type designated by one of the bases type traits.
+ BASES_TYPE is the type in question. */
+DEFTREECODE (BASES, "bases", tcc_type, 0)
+
/* Used to represent the template information stored by template
specializations.
The accessors are:
typedef enum cp_trait_kind
{
+ CPTK_BASES,
+ CPTK_DIRECT_BASES,
CPTK_HAS_NOTHROW_ASSIGN,
CPTK_HAS_NOTHROW_CONSTRUCTOR,
CPTK_HAS_NOTHROW_COPY,
#define UNDERLYING_TYPE_TYPE(NODE) \
(TYPE_VALUES_RAW (UNDERLYING_TYPE_CHECK (NODE)))
+/* The type in question for BASES. */
+#define BASES_TYPE(NODE) \
+ (TYPE_VALUES_RAW (BASES_CHECK (NODE)))
+
+#define BASES_DIRECT(NODE) \
+ TREE_LANG_FLAG_0 (BASES_CHECK (NODE))
+
/* The expression in question for a DECLTYPE_TYPE. */
#define DECLTYPE_TYPE_EXPR(NODE) (TYPE_VALUES_RAW (DECLTYPE_TYPE_CHECK (NODE)))
location_t);
extern tree finish_typeof (tree);
extern tree finish_underlying_type (tree);
+extern tree calculate_bases (tree);
+extern tree finish_bases (tree, bool);
+extern tree calculate_direct_bases (tree);
extern tree finish_offsetof (tree);
extern void finish_decl_cleanup (tree, tree);
extern void finish_eh_cleanup (tree);
case RID_UNDERLYING_TYPE:
kind = CPTK_UNDERLYING_TYPE;
break;
+ case RID_BASES:
+ kind = CPTK_BASES;
+ break;
+ case RID_DIRECT_BASES:
+ kind = CPTK_DIRECT_BASES;
+ break;
default:
gcc_unreachable ();
}
/* Complete the trait expression, which may mean either processing
the trait expr now or saving it for template instantiation. */
- return kind != CPTK_UNDERLYING_TYPE
- ? finish_trait_expr (kind, type1, type2)
- : finish_underlying_type (type1);
+ switch(kind)
+ {
+ case CPTK_UNDERLYING_TYPE:
+ return finish_underlying_type (type1);
+ case CPTK_BASES:
+ return finish_bases (type1, false);
+ case CPTK_DIRECT_BASES:
+ return finish_bases (type1, true);
+ default:
+ return finish_trait_expr (kind, type1, type2);
+ }
}
/* Lambdas that appear in variable initializer or default argument scope
parser->integral_constant_expression_p = false;
saved_non_ice_p = parser->non_integral_constant_expression_p;
parser->non_integral_constant_expression_p = false;
+
/* Parse the arguments. */
do
{
case RID_UNDERLYING_TYPE:
type = cp_parser_trait_expr (parser, RID_UNDERLYING_TYPE);
-
if (decl_specs)
cp_parser_set_decl_spec_type (decl_specs, type,
token->location,
return type;
+ case RID_BASES:
+ case RID_DIRECT_BASES:
+ type = cp_parser_trait_expr (parser, token->keyword);
+ if (decl_specs)
+ cp_parser_set_decl_spec_type (decl_specs, type,
+ token->location,
+ /*type_definition_p=*/false);
+ return type;
default:
break;
}
/* Parse a template-argument-list, as well as the trailing ">" (but
- not the opening ">"). See cp_parser_template_argument_list for the
+ not the opening "<"). See cp_parser_template_argument_list for the
return value. */
static tree
}
break;
+ case BASES:
+ parameter_pack_p = true;
+ break;
default:
/* Not a parameter pack. */
break;
tree arg_pack = NULL_TREE;
tree orig_arg = NULL_TREE;
+ if (TREE_CODE (parm_pack) == BASES)
+ {
+ if (BASES_DIRECT (parm_pack))
+ return calculate_direct_bases (tsubst_expr (BASES_TYPE (parm_pack),
+ args, complain, in_decl, false));
+ else
+ return calculate_bases (tsubst_expr (BASES_TYPE (parm_pack),
+ args, complain, in_decl, false));
+ }
if (TREE_CODE (parm_pack) == PARM_DECL)
{
if (!cp_unevaluated_operand)
return underlying_type;
}
+/* Implement the __direct_bases keyword: Return the direct base classes
+ of type */
+
+tree
+calculate_direct_bases (tree type)
+{
+ VEC(tree, gc) *vector = make_tree_vector();
+ tree bases_vec = NULL_TREE;
+ VEC(tree, none) *base_binfos;
+ tree binfo;
+ unsigned i;
+
+ complete_type (type);
+
+ if (!NON_UNION_CLASS_TYPE_P (type))
+ return make_tree_vec (0);
+
+ base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
+
+ /* Virtual bases are initialized first */
+ for (i = 0; VEC_iterate (tree, base_binfos, i, binfo); i++)
+ {
+ if (BINFO_VIRTUAL_P (binfo))
+ {
+ VEC_safe_push (tree, gc, vector, binfo);
+ }
+ }
+
+ /* Now non-virtuals */
+ for (i = 0; VEC_iterate (tree, base_binfos, i, binfo); i++)
+ {
+ if (!BINFO_VIRTUAL_P (binfo))
+ {
+ VEC_safe_push (tree, gc, vector, binfo);
+ }
+ }
+
+
+ bases_vec = make_tree_vec (VEC_length (tree, vector));
+
+ for (i = 0; i < VEC_length (tree, vector); ++i)
+ {
+ TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE (VEC_index (tree, vector, i));
+ }
+ return bases_vec;
+}
+
+/* Implement the __bases keyword: Return the base classes
+ of type */
+
+/* Find morally non-virtual base classes by walking binfo hierarchy */
+/* Virtual base classes are handled separately in finish_bases */
+
+static tree
+dfs_calculate_bases_pre (tree binfo, ATTRIBUTE_UNUSED void *data_)
+{
+ /* Don't walk bases of virtual bases */
+ return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
+}
+
+static tree
+dfs_calculate_bases_post (tree binfo, void *data_)
+{
+ VEC(tree, gc) **data = (VEC(tree, gc) **) data_;
+ if (!BINFO_VIRTUAL_P (binfo))
+ {
+ VEC_safe_push (tree, gc, *data, BINFO_TYPE (binfo));
+ }
+ return NULL_TREE;
+}
+
+/* Calculates the morally non-virtual base classes of a class */
+static VEC(tree, gc) *
+calculate_bases_helper (tree type)
+{
+ VEC(tree, gc) *vector = make_tree_vector();
+
+ /* Now add non-virtual base classes in order of construction */
+ dfs_walk_all (TYPE_BINFO (type),
+ dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
+ return vector;
+}
+
+tree
+calculate_bases (tree type)
+{
+ VEC(tree, gc) *vector = make_tree_vector();
+ tree bases_vec = NULL_TREE;
+ unsigned i;
+ VEC(tree, gc) *vbases;
+ VEC(tree, gc) *nonvbases;
+ tree binfo;
+
+ complete_type (type);
+
+ if (!NON_UNION_CLASS_TYPE_P (type))
+ return make_tree_vec (0);
+
+ /* First go through virtual base classes */
+ for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
+ VEC_iterate (tree, vbases, i, binfo); i++)
+ {
+ VEC(tree, gc) *vbase_bases = calculate_bases_helper (BINFO_TYPE (binfo));
+ VEC_safe_splice (tree, gc, vector, vbase_bases);
+ release_tree_vector (vbase_bases);
+ }
+
+ /* Now for the non-virtual bases */
+ nonvbases = calculate_bases_helper (type);
+ VEC_safe_splice (tree, gc, vector, nonvbases);
+ release_tree_vector (nonvbases);
+
+ /* Last element is entire class, so don't copy */
+ bases_vec = make_tree_vec (VEC_length (tree, vector) - 1);
+
+ for (i = 0; i < VEC_length (tree, vector) - 1; ++i)
+ {
+ TREE_VEC_ELT (bases_vec, i) = VEC_index (tree, vector, i);
+ }
+ release_tree_vector (vector);
+ return bases_vec;
+}
+
+tree
+finish_bases (tree type, bool direct)
+{
+ tree bases = NULL_TREE;
+
+ if (!processing_template_decl)
+ {
+ /* Parameter packs can only be used in templates */
+ error ("Parameter pack __bases only valid in template declaration");
+ return error_mark_node;
+ }
+
+ bases = cxx_make_type (BASES);
+ BASES_TYPE (bases) = type;
+ BASES_DIRECT (bases) = direct;
+ SET_TYPE_STRUCTURAL_EQUALITY (bases);
+
+ return bases;
+}
+
/* Perform C++-specific checks for __builtin_offsetof before calling
fold_offsetof. */
+2011-10-17 Michael Spertus <mike_spertus@symantec.com>
+
+ * g++.dg/ext/bases.C: New test.
+
2011-10-17 David S. Miller <davem@davemloft.net>
* gcc.target/sparc/fand.c: Remove __LP64__ ifdefs and expect
--- /dev/null
+// { dg-options "-std=gnu++0x -w" }
+// { dg-do run }
+
+#include<typeinfo>
+#include<cassert>
+
+// A simple typelist
+template<typename... _Elements> struct types {};
+
+// Simple bases implementation
+template<typename T> struct b {
+ typedef types<__bases(T)...> type;
+};
+
+// Simple direct_bases implementation
+template<typename T> struct db {
+ typedef types<__direct_bases(T)...> type;
+};
+
+template <class,class> struct assert_same_type;
+template <class T> struct assert_same_type<T,T> {};
+
+struct A {};
+struct C : virtual A {};
+struct D : public C {};
+struct B : D, virtual A {};
+struct E : C, virtual D, B {};
+struct F : A, B, E {};
+
+int main() {
+ assert_same_type<b<F>::type, types<A,C,D,A,C,D,B,C,C,D,B,E>>();
+ assert_same_type<db<F>::type, types<A,B,E>>();
+ assert_same_type<db<int>::type, types<>>();
+ return 0;
+}
+2011-10-17 Michael Spertus <mike_spertus@symantec.com>
+
+ * include/tr2/type_traits (bases, direct_bases, typelist): New.
+
+2011-10-17 Benjamin Kosnik <bkoz@redhat.com>
+
+ * libstdc++-v3/include/Makefile.am: Add tr2 directory and includes.
+ * libstdc++-v3/include/Makefile.in: Regenerate.
+
+ * scripts/create_testsuite_files: Search tr2 directory.
+ * testsuite/libstdc++-dg/conformance.exp: Same.
+
+ * testsuite/tr2/bases/requirements/explicit_instantiation.cc: New.
+ * testsuite/tr2/bases/requirements/typedefs.cc: New.
+ * testsuite/tr2/bases/value.cc: New.
+ * testsuite/tr2/direct_bases/requirements/
+ explicit_instantiation.cc: New.
+ * testsuite/tr2/direct_bases/requirements/typedefs.cc: New.
+ * testsuite/tr2/direct_bases/value.cc: New.
+
2011-10-17 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
PR bootstrap/50715
* testsuite/23_containers/deque/modifiers/erase/3.cc: Adjust.
2011-09-25 Benjamin Kosnik <bkoz@redhat.com>
- Jonathan Wakely <jwakely.gcc@gmail.com>
+ Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/48698
* acinclude.m4 (GLIBCXX_ENABLE_SYMVERS): Set libtool_VERSION here.
${tr1_srcdir}/wchar.h \
${tr1_srcdir}/wctype.h
+tr2_srcdir = ${glibcxx_srcdir}/include/tr2
+tr2_builddir = ./tr2
+tr2_headers = \
+ ${tr2_srcdir}/type_traits
+
decimal_srcdir = ${glibcxx_srcdir}/include/decimal
decimal_builddir = ./decimal
decimal_headers = \
# CLEANFILES and all-local are kept up-to-date.
allstamped = \
stamp-std stamp-bits stamp-bits-sup stamp-c_base stamp-c_compatibility \
- stamp-backward stamp-ext stamp-pb stamp-tr1 stamp-decimal \
+ stamp-backward stamp-ext stamp-pb stamp-tr1 stamp-tr2 stamp-decimal \
stamp-debug stamp-parallel stamp-profile stamp-profile-impl \
stamp-host
@-cd ${tr1_builddir} && $(LN_S) $? . 2>/dev/null
@$(STAMP) stamp-tr1
+stamp-tr2: ${tr2_headers}
+ @-mkdir -p ${tr2_builddir}
+ @-cd ${tr2_builddir} && $(LN_S) $? . 2>/dev/null
+ @$(STAMP) stamp-tr2
+
stamp-decimal: ${decimal_headers}
@-mkdir -p ${decimal_builddir}
@-cd ${decimal_builddir} && $(LN_S) $? . 2>/dev/null
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_builddir}
for file in ${tr1_headers}; do \
$(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_builddir}; done
+ $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr2_builddir}
+ for file in ${tr2_headers}; do \
+ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr2_builddir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${decimal_builddir}
for file in ${decimal_headers}; do \
$(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${decimal_builddir}; done
# developer tries to create them via make in the include build
# directory. (This is more of an example of how this kind of rule can
# be made.)
-.PRECIOUS: $(std_headers) $(c_base_headers) $(tr1_headers)
+.PRECIOUS: $(std_headers) $(c_base_headers) $(tr1_headers) $(tr2_headers)
$(decimal_headers) $(ext_headers)
$(std_headers): ; @:
$(c_base_headers): ; @:
${tr1_srcdir}/wchar.h \
${tr1_srcdir}/wctype.h
+tr2_srcdir = ${glibcxx_srcdir}/include/tr2
+tr2_builddir = ./tr2
+tr2_headers = \
+ ${tr2_srcdir}/type_traits
+
decimal_srcdir = ${glibcxx_srcdir}/include/decimal
decimal_builddir = ./decimal
decimal_headers = \
# CLEANFILES and all-local are kept up-to-date.
allstamped = \
stamp-std stamp-bits stamp-bits-sup stamp-c_base stamp-c_compatibility \
- stamp-backward stamp-ext stamp-pb stamp-tr1 stamp-decimal \
+ stamp-backward stamp-ext stamp-pb stamp-tr1 stamp-tr2 stamp-decimal \
stamp-debug stamp-parallel stamp-profile stamp-profile-impl \
stamp-host
@-cd ${tr1_builddir} && $(LN_S) $? . 2>/dev/null
@$(STAMP) stamp-tr1
+stamp-tr2: ${tr2_headers}
+ @-mkdir -p ${tr2_builddir}
+ @-cd ${tr2_builddir} && $(LN_S) $? . 2>/dev/null
+ @$(STAMP) stamp-tr2
+
stamp-decimal: ${decimal_headers}
@-mkdir -p ${decimal_builddir}
@-cd ${decimal_builddir} && $(LN_S) $? . 2>/dev/null
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr1_builddir}
for file in ${tr1_headers}; do \
$(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr1_builddir}; done
+ $(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${tr2_builddir}
+ for file in ${tr2_headers}; do \
+ $(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${tr2_builddir}; done
$(mkinstalldirs) $(DESTDIR)${gxx_include_dir}/${decimal_builddir}
for file in ${decimal_headers}; do \
$(INSTALL_DATA) $${file} $(DESTDIR)${gxx_include_dir}/${decimal_builddir}; done
# developer tries to create them via make in the include build
# directory. (This is more of an example of how this kind of rule can
# be made.)
-.PRECIOUS: $(std_headers) $(c_base_headers) $(tr1_headers)
+.PRECIOUS: $(std_headers) $(c_base_headers) $(tr1_headers) $(tr2_headers)
$(decimal_headers) $(ext_headers)
$(std_headers): ; @:
$(c_base_headers): ; @:
--- /dev/null
+// TR2 type_traits -*- C++ -*-
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file tr2/type_traits
+ * This is a TR2 C++ Library header.
+ */
+
+#ifndef _GLIBCXX_TR2_TYPE_TRAITS
+#define _GLIBCXX_TR2_TYPE_TRAITS 1
+
+#pragma GCC system_header
+#include <type_traits>
+#include <bits/c++config.h>
+
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+namespace tr2
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ /**
+ * @defgroup metaprogramming Type Traits
+ * @ingroup utilities
+ *
+ * Compile time type transformation and information.
+ * @{
+ */
+
+ template<typename... _Elements>
+ struct typelist;
+
+ template<>
+ struct typelist<>
+ {
+ typedef std::true_type empty;
+ };
+
+ template<typename _First, typename... _Rest>
+ struct typelist<_First, _Rest...>
+ {
+ typedef std::false_type empty;
+
+ struct first
+ {
+ typedef _First type;
+ };
+
+ struct rest
+ {
+ typedef typelist<_Rest...> type;
+ };
+ };
+
+ // Sequence abstraction metafunctions default to looking in the type
+ template<typename _Tp>
+ struct first : public _Tp::first { };
+
+ template<typename _Tp>
+ struct rest : public _Tp::rest { };
+
+ template<typename _Tp>
+ struct empty : public _Tp::empty { };
+
+
+ template<typename _Tp>
+ struct bases
+ {
+ typedef typelist<__bases(_Tp)...> type;
+ };
+
+ template<typename _Tp>
+ struct direct_bases
+ {
+ typedef typelist<__direct_bases(_Tp)...> type;
+ };
+
+_GLIBCXX_END_NAMESPACE_VERSION
+}
+}
+
+#endif // _GLIBCXX_TR2_TYPE_TRAITS
# This is the ugly version of "everything but the current directory". It's
# what has to happen when find(1) doesn't support -mindepth, or -xtype.
dlist=`echo [0-9][0-9]*`
-dlist="$dlist abi backward ext performance tr1 decimal"
+dlist="$dlist abi backward ext performance tr1 tr2 decimal"
find $dlist "(" -type f -o -type l ")" -name "*.cc" -print > $tmp.01
find $dlist "(" -type f -o -type l ")" -name "*.c" -print > $tmp.02
cat $tmp.01 $tmp.02 | sort > $tmp.1
lappend subdirs "$srcdir/ext"
lappend subdirs "$srcdir/performance"
lappend subdirs "$srcdir/tr1"
+ lappend subdirs "$srcdir/tr2"
lappend subdirs "$srcdir/decimal"
verbose "subdirs are $subdirs"
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <tr2/type_traits>
+
+namespace std
+{
+ namespace tr2
+ {
+ typedef short test_type;
+ template struct bases<test_type>;
+ }
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+//
+// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES.
+
+#include <tr2/type_traits>
+
+void test01()
+{
+ // Check for required typedefs
+ typedef std::tr2::bases<int> test_type;
+ typedef test_type::type value_type;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+//
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <tr2/type_traits>
+#include <typeinfo>
+#include <stdexcept>
+
+struct A { };
+struct B1 : virtual public A { };
+struct B2 : virtual public A { };
+struct C : public B1, public B2 { };
+
+void test()
+{
+ bool test __attribute__((unused)) = true;
+
+ // 1
+ {
+ typedef std::tr2::bases<A>::type tl;
+ static_assert(tl::empty::value, "error");
+ }
+
+ // 2
+ {
+ typedef std::tr2::bases<B1>::type tl1;
+ typedef std::tr2::bases<B2>::type tl2;
+
+ // Sanity check w/ runtime.
+ bool eq = typeid(tl1) == typeid(tl2);
+ if (!eq)
+ throw std::logic_error("typelist not equal");
+
+ // Sanity check.
+ static_assert(tl1::empty::value != std::true_type::value, "!empty");
+ static_assert(tl2::empty::value != std::true_type::value, "!empty");
+
+ typedef tl1::first::type tl1_first;
+ typedef tl1::rest::type tl1_rest;
+ typedef tl2::first::type tl2_first;
+ typedef tl2::rest::type tl2_rest;
+
+ eq = typeid(tl1_first) == typeid(tl2_first);
+ if (!eq)
+ throw std::logic_error("base not equal");
+
+ static_assert(tl1_rest::empty::value == std::true_type::value, "empty");
+ static_assert(tl2_rest::empty::value == std::true_type::value, "empty");
+ }
+
+ // 3
+ {
+ typedef std::tr2::bases<C>::type tl;
+
+ // Sanity check.
+ static_assert(tl::empty::value != std::true_type::value, "!empty");
+
+ typedef tl::first::type tl1_first;
+ typedef tl::rest::type tl2;
+ typedef tl2::first::type tl2_first;
+ typedef tl2::rest::type tl3;
+ typedef tl3::first::type tl3_first;
+ typedef tl3::rest::type tl4;
+
+ bool eq = typeid(tl1_first) == typeid(tl2_first);
+ if (eq)
+ throw std::logic_error("bases are not equal");
+
+ eq = typeid(tl2_first) == typeid(tl3_first);
+ if (eq)
+ throw std::logic_error("bases are not equal");
+
+ static_assert(tl4::empty::value == std::true_type::value, "empty");
+ }
+
+}
+
+int main()
+{
+ test();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <tr2/type_traits>
+
+namespace std
+{
+ namespace tr2
+ {
+ typedef short test_type;
+ template struct direct_bases<test_type>;
+ }
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+// { dg-do compile }
+
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+//
+// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES.
+
+#include <tr2/type_traits>
+
+void test01()
+{
+ // Check for required typedefs
+ typedef std::tr2::direct_bases<int> test_type;
+ typedef test_type::type value_type;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+//
+// Copyright (C) 2011 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <tr2/type_traits>
+#include <typeinfo>
+#include <stdexcept>
+
+struct A { };
+struct B1 : virtual public A { };
+struct B2 : virtual public A { };
+struct C : public B1, public B2 { };
+
+void test()
+{
+ bool test __attribute__((unused)) = true;
+
+ // 1
+ {
+ typedef std::tr2::direct_bases<A>::type tl;
+ static_assert(tl::empty::value, "error");
+ }
+
+ // 2
+ {
+ typedef std::tr2::direct_bases<B1>::type tl1;
+ typedef std::tr2::direct_bases<B2>::type tl2;
+
+ // Sanity check w/ runtime.
+ bool eq = typeid(tl1) == typeid(tl2);
+ if (!eq)
+ throw std::logic_error("typelist not equal");
+
+ // Sanity check.
+ static_assert(tl1::empty::value != std::true_type::value, "!empty");
+ static_assert(tl2::empty::value != std::true_type::value, "!empty");
+
+ typedef tl1::first::type tl1_first;
+ typedef tl1::rest::type tl1_rest;
+ typedef tl2::first::type tl2_first;
+ typedef tl2::rest::type tl2_rest;
+
+ eq = typeid(tl1_first) == typeid(tl2_first);
+ if (!eq)
+ throw std::logic_error("base not equal");
+
+ static_assert(tl1_rest::empty::value == std::true_type::value, "empty");
+ static_assert(tl2_rest::empty::value == std::true_type::value, "empty");
+ }
+
+ // 3
+ {
+ typedef std::tr2::direct_bases<C>::type tl;
+
+ // Sanity check.
+ static_assert(tl::empty::value != std::true_type::value, "!empty");
+
+ typedef tl::first::type tl1_first;
+ typedef tl::rest::type tl2;
+ typedef tl2::first::type tl2_first;
+ typedef tl2::rest::type tl3;
+
+ bool eq = typeid(tl1_first) == typeid(tl2_first);
+ if (eq)
+ throw std::logic_error("bases are not equal");
+
+ static_assert(tl3::empty::value == std::true_type::value, "empty");
+ }
+
+}
+
+int main()
+{
+ test();
+ return 0;
+}