From eb8c2b30b947dd8a2012ee658117bea05e46bc85 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 3 Dec 2020 08:58:44 -0800 Subject: [PATCH] c++: templatey type creation This patch makes a couple of type-creation routines available to modules. That needs to create unbound template parms, and canonical template parms. gcc/cp/ * cp-tree.h (make_unbound_class_template_raw): Declare. (canonical_type_parameter): Declare. * decl.c (make_unbound_class_template_raw): Break out of ... (make_unboud_class_template): ... here. Call it. * pt.c (canonical_type_parameter): Externalize. Refactor & set structural_equality for type parms. --- gcc/cp/cp-tree.h | 2 ++ gcc/cp/decl.c | 8 ++++++++ gcc/cp/pt.c | 27 ++++++++++++++++----------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index de905dcf37c..69f8ed56e62 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6542,6 +6542,7 @@ extern bool check_omp_return (void); extern tree make_typename_type (tree, tree, enum tag_types, tsubst_flags_t); extern tree build_typename_type (tree, tree, tree, tag_types); extern tree make_unbound_class_template (tree, tree, tree, tsubst_flags_t); +extern tree make_unbound_class_template_raw (tree, tree, tree); extern tree build_library_fn_ptr (const char *, tree, int); extern tree build_cp_library_fn_ptr (const char *, tree, int); extern tree push_library_fn (tree, tree, tree, int); @@ -6880,6 +6881,7 @@ extern void maybe_show_extern_c_location (void); extern bool literal_integer_zerop (const_tree); /* in pt.c */ +extern tree canonical_type_parameter (tree); extern void push_access_scope (tree); extern void pop_access_scope (tree); extern bool check_template_shadow (tree); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 0cf84a0750c..a28e7924869 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4132,6 +4132,14 @@ make_unbound_class_template (tree context, tree name, tree parm_list, return tmpl; } + return make_unbound_class_template_raw (context, name, parm_list); +} + +/* Build an UNBOUND_CLASS_TEMPLATE. */ + +tree +make_unbound_class_template_raw (tree context, tree name, tree parm_list) +{ /* Build the UNBOUND_CLASS_TEMPLATE. */ tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE); TYPE_CONTEXT (t) = FROB_CONTEXT (context); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 66ac6473983..3ca28133d94 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -4432,7 +4432,7 @@ build_template_parm_index (int index, parameter. Returns the canonical type parameter, which may be TYPE if no such parameter existed. */ -static tree +tree canonical_type_parameter (tree type) { int idx = TEMPLATE_TYPE_IDX (type); @@ -13212,19 +13212,24 @@ tsubst_argument_pack (tree orig_arg, tree args, tsubst_flags_t complain, tree in_decl) { /* Substitute into each of the arguments. */ - tree new_arg = TYPE_P (orig_arg) - ? cxx_make_type (TREE_CODE (orig_arg)) - : make_node (TREE_CODE (orig_arg)); - tree pack_args = tsubst_template_args (ARGUMENT_PACK_ARGS (orig_arg), args, complain, in_decl); - if (pack_args == error_mark_node) - new_arg = error_mark_node; - else - SET_ARGUMENT_PACK_ARGS (new_arg, pack_args); + tree new_arg = error_mark_node; + if (pack_args != error_mark_node) + { + if (TYPE_P (orig_arg)) + { + new_arg = cxx_make_type (TREE_CODE (orig_arg)); + SET_TYPE_STRUCTURAL_EQUALITY (new_arg); + } + else + { + new_arg = make_node (TREE_CODE (orig_arg)); + TREE_CONSTANT (new_arg) = TREE_CONSTANT (orig_arg); + } - if (TREE_CODE (new_arg) == NONTYPE_ARGUMENT_PACK) - TREE_CONSTANT (new_arg) = TREE_CONSTANT (orig_arg); + SET_ARGUMENT_PACK_ARGS (new_arg, pack_args); + } return new_arg; } -- 2.30.2