diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ddc5149..6c73404 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2011-10-17 Michael Spertus + + * 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 Ian Lance Taylor diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 0aa0fef..9d20d80 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -423,6 +423,7 @@ const struct c_common_resword c_common_reswords[] = { "__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 }, @@ -434,6 +435,7 @@ const struct c_common_resword c_common_reswords[] = { "__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 }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 8996eef..9818c9c 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -128,12 +128,13 @@ enum rid 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, diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ed7d832..2a4bdbb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,16 @@ +2011-10-17 Michael Spertus + + * 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 PR c++/50736 diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def index be29870..4eec9f9 100644 --- a/gcc/cp/cp-tree.def +++ b/gcc/cp/cp-tree.def @@ -462,6 +462,10 @@ DEFTREECODE (DECLTYPE_TYPE, "decltype_type", tcc_type, 0) 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: diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 88f7fbd..bda18d9 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -564,6 +564,8 @@ struct GTY (()) tree_argument_pack_select { typedef enum cp_trait_kind { + CPTK_BASES, + CPTK_DIRECT_BASES, CPTK_HAS_NOTHROW_ASSIGN, CPTK_HAS_NOTHROW_CONSTRUCTOR, CPTK_HAS_NOTHROW_COPY, @@ -3433,6 +3435,13 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) #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))) @@ -5462,6 +5471,9 @@ extern tree finish_id_expression (tree, tree, tree, 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); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index bf362f2..c0e9001 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7304,6 +7304,12 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword) 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 (); } @@ -7348,9 +7354,17 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword) /* 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 @@ -12040,6 +12054,7 @@ cp_parser_template_argument_list (cp_parser* parser) 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 { @@ -12857,7 +12872,6 @@ cp_parser_simple_type_specifier (cp_parser* parser, 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, @@ -12865,6 +12879,14 @@ cp_parser_simple_type_specifier (cp_parser* parser, 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; } @@ -20652,7 +20674,7 @@ cp_parser_save_nsdmi (cp_parser* parser) /* 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 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bbe1139..6fc60d5 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2980,6 +2980,9 @@ find_parameter_packs_r (tree *tp, int *walk_subtrees, void* data) } break; + case BASES: + parameter_pack_p = true; + break; default: /* Not a parameter pack. */ break; @@ -9127,6 +9130,15 @@ tsubst_pack_expansion (tree t, tree args, tsubst_flags_t complain, 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) diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 1efe579..3e847fa 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3394,6 +3394,149 @@ finish_underlying_type (tree type) 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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 500c142..39efdcc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-10-17 Michael Spertus + + * g++.dg/ext/bases.C: New test. + 2011-10-17 David S. Miller * gcc.target/sparc/fand.c: Remove __LP64__ ifdefs and expect diff --git a/gcc/testsuite/g++.dg/ext/bases.C b/gcc/testsuite/g++.dg/ext/bases.C new file mode 100644 index 0000000..0582f72 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/bases.C @@ -0,0 +1,35 @@ +// { dg-options "-std=gnu++0x -w" } +// { dg-do run } + +#include +#include + +// A simple typelist +template struct types {}; + +// Simple bases implementation +template struct b { + typedef types<__bases(T)...> type; +}; + +// Simple direct_bases implementation +template struct db { + typedef types<__direct_bases(T)...> type; +}; + +template struct assert_same_type; +template struct assert_same_type {}; + +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::type, types>(); + assert_same_type::type, types>(); + assert_same_type::type, types<>>(); + return 0; +} diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e8a621a..3baca8c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,23 @@ +2011-10-17 Michael Spertus + + * include/tr2/type_traits (bases, direct_bases, typelist): New. + +2011-10-17 Benjamin Kosnik + + * 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 PR bootstrap/50715 @@ -194,7 +214,7 @@ * testsuite/23_containers/deque/modifiers/erase/3.cc: Adjust. 2011-09-25 Benjamin Kosnik - Jonathan Wakely + Jonathan Wakely PR libstdc++/48698 * acinclude.m4 (GLIBCXX_ENABLE_SYMVERS): Set libtool_VERSION here. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 4016882..9fdaa8d 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -604,6 +604,11 @@ tr1_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 = \ @@ -887,7 +892,7 @@ endif # 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 @@ -1002,6 +1007,11 @@ stamp-tr1: ${tr1_headers} @-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 @@ -1245,6 +1255,9 @@ install-headers: $(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 @@ -1291,7 +1304,7 @@ clean-local: # 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): ; @: diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 58dbfc4..5ad5932 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -854,6 +854,11 @@ tr1_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 = \ @@ -1125,7 +1130,7 @@ PCHFLAGS = -x c++-header -nostdinc++ $(CXXFLAGS) # 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 @@ -1402,6 +1407,11 @@ stamp-tr1: ${tr1_headers} @-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 @@ -1630,6 +1640,9 @@ install-headers: $(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 @@ -1673,7 +1686,7 @@ clean-local: # 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): ; @: diff --git a/libstdc++-v3/include/tr2/type_traits b/libstdc++-v3/include/tr2/type_traits new file mode 100644 index 0000000..e860ad7 --- /dev/null +++ b/libstdc++-v3/include/tr2/type_traits @@ -0,0 +1,102 @@ +// 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 +// . + +/** @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 +#include + +namespace std _GLIBCXX_VISIBILITY(default) +{ +namespace tr2 +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /** + * @defgroup metaprogramming Type Traits + * @ingroup utilities + * + * Compile time type transformation and information. + * @{ + */ + + template + struct typelist; + + template<> + struct typelist<> + { + typedef std::true_type empty; + }; + + template + 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 + struct first : public _Tp::first { }; + + template + struct rest : public _Tp::rest { }; + + template + struct empty : public _Tp::empty { }; + + + template + struct bases + { + typedef typelist<__bases(_Tp)...> type; + }; + + template + struct direct_bases + { + typedef typelist<__direct_bases(_Tp)...> type; + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} +} + +#endif // _GLIBCXX_TR2_TYPE_TRAITS diff --git a/libstdc++-v3/scripts/create_testsuite_files b/libstdc++-v3/scripts/create_testsuite_files index f4a0bcd..a427eef 100755 --- a/libstdc++-v3/scripts/create_testsuite_files +++ b/libstdc++-v3/scripts/create_testsuite_files @@ -32,7 +32,7 @@ cd $srcdir # 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 diff --git a/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp b/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp index 8642eb7..19fa0e2 100644 --- a/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp +++ b/libstdc++-v3/testsuite/libstdc++-dg/conformance.exp @@ -58,6 +58,7 @@ if {[info exists tests_file] && [file exists $tests_file]} { lappend subdirs "$srcdir/ext" lappend subdirs "$srcdir/performance" lappend subdirs "$srcdir/tr1" + lappend subdirs "$srcdir/tr2" lappend subdirs "$srcdir/decimal" verbose "subdirs are $subdirs" diff --git a/libstdc++-v3/testsuite/tr2/bases/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/tr2/bases/requirements/explicit_instantiation.cc new file mode 100644 index 0000000..ddd6d6f --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/bases/requirements/explicit_instantiation.cc @@ -0,0 +1,32 @@ +// { 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 +// . + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +namespace std +{ + namespace tr2 + { + typedef short test_type; + template struct bases; + } +} diff --git a/libstdc++-v3/testsuite/tr2/bases/requirements/typedefs.cc b/libstdc++-v3/testsuite/tr2/bases/requirements/typedefs.cc new file mode 100644 index 0000000..a62acff --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/bases/requirements/typedefs.cc @@ -0,0 +1,31 @@ +// { 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 +// . + +// +// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES. + +#include + +void test01() +{ + // Check for required typedefs + typedef std::tr2::bases test_type; + typedef test_type::type value_type; +} diff --git a/libstdc++-v3/testsuite/tr2/bases/value.cc b/libstdc++-v3/testsuite/tr2/bases/value.cc new file mode 100644 index 0000000..415e974 --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/bases/value.cc @@ -0,0 +1,97 @@ +// { 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 +// . + +#include +#include +#include + +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::type tl; + static_assert(tl::empty::value, "error"); + } + + // 2 + { + typedef std::tr2::bases::type tl1; + typedef std::tr2::bases::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::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; +} diff --git a/libstdc++-v3/testsuite/tr2/direct_bases/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/tr2/direct_bases/requirements/explicit_instantiation.cc new file mode 100644 index 0000000..d7fb96a --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/direct_bases/requirements/explicit_instantiation.cc @@ -0,0 +1,32 @@ +// { 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 +// . + +// NB: This file is for testing type_traits with NO OTHER INCLUDES. + +#include + +namespace std +{ + namespace tr2 + { + typedef short test_type; + template struct direct_bases; + } +} diff --git a/libstdc++-v3/testsuite/tr2/direct_bases/requirements/typedefs.cc b/libstdc++-v3/testsuite/tr2/direct_bases/requirements/typedefs.cc new file mode 100644 index 0000000..7d219ea --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/direct_bases/requirements/typedefs.cc @@ -0,0 +1,31 @@ +// { 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 +// . + +// +// NB: This file is for testing tr1/type_traits with NO OTHER INCLUDES. + +#include + +void test01() +{ + // Check for required typedefs + typedef std::tr2::direct_bases test_type; + typedef test_type::type value_type; +} diff --git a/libstdc++-v3/testsuite/tr2/direct_bases/value.cc b/libstdc++-v3/testsuite/tr2/direct_bases/value.cc new file mode 100644 index 0000000..81d0269 --- /dev/null +++ b/libstdc++-v3/testsuite/tr2/direct_bases/value.cc @@ -0,0 +1,91 @@ +// { 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 +// . + +#include +#include +#include + +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::type tl; + static_assert(tl::empty::value, "error"); + } + + // 2 + { + typedef std::tr2::direct_bases::type tl1; + typedef std::tr2::direct_bases::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::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; +}