Commit cd057e3a by Jason Merrill Committed by Jason Merrill

PR c++/51213 (again)

	PR c++/51213 (again)
	* pt.c (deduction_tsubst_fntype): Remove.
	(fn_type_unification): Check deduction depth and call
	instantiate_template here.  Handle default argument access checks.
	(determine_specialization): Suppress access control.
	(tsubst_decl): Check for excessive deduction depth.
	(recheck_decl_substitution): Make sure access control is on.
	(type_unification_real): Don't mess with access deferring here.
	(get_bindings): Adjust for fn_type_unification return type.
	* call.c (enum rejection_reason_code): Drop rr_template_instantiation.
	(template_instantiation_rejection): Remove.
	(struct rejection_reason): Change targs to num_targs.
	(template_unification_rejection, print_z_candidate): Adjust.
	(add_template_candidate_real): Adjust for fn_type_unification change.
	* class.c (resolve_address_of_overloaded_function): Likewise.
	* cp-tree.h: Adjust declaration.

From-SVN: r190664
parent f581a987
2012-08-24 Jason Merrill <jason@redhat.com>
PR c++/51213 (again)
* pt.c (deduction_tsubst_fntype): Remove.
(fn_type_unification): Check deduction depth and call
instantiate_template here. Handle default argument access checks.
(determine_specialization): Suppress access control.
(tsubst_decl): Check for excessive deduction depth.
(recheck_decl_substitution): Make sure access control is on.
(type_unification_real): Don't mess with access deferring here.
(get_bindings): Adjust for fn_type_unification return type.
* call.c (enum rejection_reason_code): Drop rr_template_instantiation.
(template_instantiation_rejection): Remove.
(struct rejection_reason): Change targs to num_targs.
(template_unification_rejection, print_z_candidate): Adjust.
(add_template_candidate_real): Adjust for fn_type_unification change.
* class.c (resolve_address_of_overloaded_function): Likewise.
* cp-tree.h: Adjust declaration.
* pt.c (tsubst_default_argument): Indicate where the default
argument is being instantiated for.
(tsubst_expr): Restore previous location.
......
......@@ -451,7 +451,6 @@ enum rejection_reason_code {
rr_arg_conversion,
rr_bad_arg_conversion,
rr_template_unification,
rr_template_instantiation,
rr_invalid_copy
};
......@@ -485,7 +484,7 @@ struct rejection_reason {
struct {
tree tmpl;
tree explicit_targs;
tree targs;
int num_targs;
const tree *args;
unsigned int nargs;
tree return_type;
......@@ -688,7 +687,7 @@ template_unification_rejection (tree tmpl, tree explicit_targs, tree targs,
struct rejection_reason *r = alloc_rejection (rr_template_unification);
r->u.template_unification.tmpl = tmpl;
r->u.template_unification.explicit_targs = explicit_targs;
r->u.template_unification.targs = targs;
r->u.template_unification.num_targs = TREE_VEC_LENGTH (targs);
/* Copy args to our own storage. */
memcpy (args1, args, args_n_bytes);
r->u.template_unification.args = args1;
......@@ -706,15 +705,6 @@ template_unification_error_rejection (void)
}
static struct rejection_reason *
template_instantiation_rejection (tree tmpl, tree targs)
{
struct rejection_reason *r = alloc_rejection (rr_template_instantiation);
r->u.template_instantiation.tmpl = tmpl;
r->u.template_instantiation.targs = targs;
return r;
}
static struct rejection_reason *
invalid_copy_with_fn_template_rejection (void)
{
struct rejection_reason *r = alloc_rejection (rr_invalid_copy);
......@@ -2873,7 +2863,6 @@ add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
unsigned int ia, ix;
tree arg;
struct z_candidate *cand;
int i;
tree fn;
struct rejection_reason *reason = NULL;
int errs;
......@@ -2920,12 +2909,12 @@ add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
gcc_assert (ia == nargs_without_in_chrg);
errs = errorcount+sorrycount;
i = fn_type_unification (tmpl, explicit_targs, targs,
args_without_in_chrg,
nargs_without_in_chrg,
return_type, strict, flags, false);
fn = fn_type_unification (tmpl, explicit_targs, targs,
args_without_in_chrg,
nargs_without_in_chrg,
return_type, strict, flags, false);
if (i != 0)
if (fn == error_mark_node)
{
/* Don't repeat unification later if it already resulted in errors. */
if (errorcount+sorrycount == errs)
......@@ -2938,13 +2927,6 @@ add_template_candidate_real (struct z_candidate **candidates, tree tmpl,
goto fail;
}
fn = instantiate_template (tmpl, targs, tf_none);
if (fn == error_mark_node)
{
reason = template_instantiation_rejection (tmpl, targs);
goto fail;
}
/* In [class.copy]:
A member function template is never instantiated to perform the
......@@ -3239,7 +3221,8 @@ print_z_candidate (location_t loc, const char *msgstr,
inform (cloc, " template argument deduction/substitution failed:");
fn_type_unification (r->u.template_unification.tmpl,
r->u.template_unification.explicit_targs,
r->u.template_unification.targs,
(make_tree_vec
(r->u.template_unification.num_targs)),
r->u.template_unification.args,
r->u.template_unification.nargs,
r->u.template_unification.return_type,
......@@ -3247,12 +3230,6 @@ print_z_candidate (location_t loc, const char *msgstr,
r->u.template_unification.flags,
true);
break;
case rr_template_instantiation:
/* Re-run template instantiation with diagnostics. */
instantiate_template (r->u.template_instantiation.tmpl,
r->u.template_instantiation.targs,
tf_warning_or_error);
break;
case rr_invalid_copy:
inform (cloc,
" a constructor taking a single argument of its own "
......
......@@ -7033,14 +7033,10 @@ resolve_address_of_overloaded_function (tree target_type,
/* Try to do argument deduction. */
targs = make_tree_vec (DECL_NTPARMS (fn));
if (fn_type_unification (fn, explicit_targs, targs, args, nargs,
target_ret_type, DEDUCE_EXACT,
LOOKUP_NORMAL, false))
/* Argument deduction failed. */
continue;
/* Instantiate the template. */
instantiation = instantiate_template (fn, targs, flags);
instantiation = fn_type_unification (fn, explicit_targs, targs, args,
nargs, target_ret_type,
DEDUCE_EXACT, LOOKUP_NORMAL,
false);
if (instantiation == error_mark_node)
/* Instantiation failed. */
continue;
......
......@@ -5340,7 +5340,7 @@ extern int uses_template_parms_level (tree, int);
extern bool in_template_function (void);
extern tree instantiate_class_template (tree);
extern tree instantiate_template (tree, tree, tsubst_flags_t);
extern int fn_type_unification (tree, tree, tree,
extern tree fn_type_unification (tree, tree, tree,
const tree *, unsigned int,
tree, unification_kind_t, int,
bool);
......
// { dg-do compile { target c++11 } }
template <class T, class = typename T::I> void f(T) {}
template <class T, class = typename T::I> void g(T) {}
// template <class T, class = typename T::I> void h(T) {}
// template <class T, class = typename T::I> void i(T) {}
template <class T, class = typename T::I> void j(T) {} // { dg-error "this context" }
class A
{
typedef int I; // { dg-error "private" }
template <class T, class> friend void f(T);
friend void g<A,I>(A);
// friend void h<A>(A);
// friend void i<>(A);
};
int main()
{
A a;
f(a);
g(a);
// h(a);
// i(a);
j(a); // { dg-error "no match" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment