static tree tsubst_template_args (tree, tree, tsubst_flags_t, tree);
static tree tsubst_template_parms (tree, tree, tsubst_flags_t);
static void regenerate_decl_from_template (tree, tree);
-static tree most_specialized (tree, tree, tree);
static tree most_specialized_class (tree, tree);
static tree tsubst_aggr_type (tree, tree, tsubst_flags_t, tree, int);
static tree tsubst_arg_types (tree, tree, tsubst_flags_t, tree);
tree targs;
tree explicit_targs;
tree candidates = NULL_TREE;
+ /* A TREE_LIST of templates of which DECL may be a specialization.
+ The TREE_VALUE of each node is a TEMPLATE_DECL. The
+ corresponding TREE_PURPOSE is the set of template arguments that,
+ when used to instantiate the template, would produce a function
+ with the signature of DECL. */
tree templates = NULL_TREE;
int header_count;
struct cp_binding_level *b;
the EDG front-end has that behavior, and John Spicer claims
that the committee simply forgot to delete the wording in
[temp.expl.spec]. */
- tree tmpl = most_specialized (templates, decl, explicit_targs);
- if (tmpl && tmpl != error_mark_node)
- {
- targs = get_bindings (tmpl, decl, explicit_targs, /*check_ret=*/true);
- templates = tree_cons (targs, tmpl, NULL_TREE);
- }
+ tree tmpl = most_specialized_instantiation (templates);
+ if (tmpl != error_mark_node)
+ {
+ templates = tmpl;
+ TREE_CHAIN (templates) = NULL_TREE;
+ }
}
if (templates == NULL_TREE && candidates == NULL_TREE)
return vec;
}
-/* In INSTANTIATIONS is a list of <INSTANTIATION, TEMPLATE> pairs.
- Pick the most specialized template, and return the corresponding
- instantiation, or if there is no corresponding instantiation, the
- template itself. If there is no most specialized template,
- error_mark_node is returned. If there are no templates at all,
- NULL_TREE is returned. */
+/* TEMPLATES is a TREE_LIST. Each TREE_VALUE is a TEMPLATE_DECL.
+ Return the TREE_LIST node with the most specialized template, if
+ any. If there is no most specialized template, the error_mark_node
+ is returned.
+
+ Note that this function does not look at, or modify, the
+ TREE_PURPOSE or TREE_TYPE of any of the nodes. Since the node
+ returned is one of the elements of INSTANTIATIONS, callers may
+ store information in the TREE_PURPOSE or TREE_TYPE of the nodes,
+ and retrieve it from the value returned. */
tree
-most_specialized_instantiation (tree instantiations)
+most_specialized_instantiation (tree templates)
{
tree fn, champ;
- if (!instantiations)
- return NULL_TREE;
-
++processing_template_decl;
- champ = instantiations;
- for (fn = TREE_CHAIN (instantiations); fn; fn = TREE_CHAIN (fn))
+ champ = templates;
+ for (fn = TREE_CHAIN (templates); fn; fn = TREE_CHAIN (fn))
{
int fate = 0;
/* Equally specialized, move to next function. If there
is no next function, nothing's most specialized. */
fn = TREE_CHAIN (fn);
+ champ = fn;
if (!fn)
break;
}
if (champ)
/* Now verify that champ is better than everything earlier in the
instantiation list. */
- for (fn = instantiations; fn != champ; fn = TREE_CHAIN (fn))
+ for (fn = templates; fn != champ; fn = TREE_CHAIN (fn))
if (get_bindings (TREE_VALUE (champ),
DECL_TEMPLATE_RESULT (TREE_VALUE (fn)),
NULL_TREE, /*check_ret=*/false)
if (!champ)
return error_mark_node;
- return TREE_PURPOSE (champ) ? TREE_PURPOSE (champ) : TREE_VALUE (champ);
-}
-
-/* Return the most specialized of the list of templates in FNS that can
- produce an instantiation matching DECL, given the explicit template
- arguments EXPLICIT_ARGS. */
-
-static tree
-most_specialized (tree fns, tree decl, tree explicit_args)
-{
- tree candidates = NULL_TREE;
- tree fn, args;
-
- for (fn = fns; fn; fn = TREE_CHAIN (fn))
- {
- tree candidate = TREE_VALUE (fn);
-
- args = get_bindings (candidate, decl, explicit_args, /*check_ret=*/true);
- if (args)
- candidates = tree_cons (NULL_TREE, candidate, candidates);
- }
-
- return most_specialized_instantiation (candidates);
+ return champ;
}
/* If DECL is a specialization of some template, return the most