Commit 8f96c7ac by Jason Merrill Committed by Jason Merrill

call.c (add_function_candidate): Check for proper number of args before checking…

call.c (add_function_candidate): Check for proper number of args before checking the validity of those args.

	* call.c (add_function_candidate): Check for proper number of args
	before checking the validity of those args.

From-SVN: r25660
parent 19f019c2
1999-03-09 Jason Merrill <jason@yorick.cygnus.com>
* call.c (add_function_candidate): Check for proper number of args
before checking the validity of those args.
1999-03-06 Jason Merrill <jason@yorick.cygnus.com> 1999-03-06 Jason Merrill <jason@yorick.cygnus.com>
* cp-tree.h (struct lang_type): Add anon_union field. * cp-tree.h (struct lang_type): Add anon_union field.
......
...@@ -1134,24 +1134,60 @@ add_function_candidate (candidates, fn, arglist, flags) ...@@ -1134,24 +1134,60 @@ add_function_candidate (candidates, fn, arglist, flags)
tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn)); tree parmlist = TYPE_ARG_TYPES (TREE_TYPE (fn));
int i, len; int i, len;
tree convs; tree convs;
tree parmnode = parmlist; tree parmnode, argnode;
tree argnode = arglist;
int viable = 1; int viable = 1;
/* The `this' and `in_chrg' arguments to constructors are not considered /* The `this' and `in_chrg' arguments to constructors are not considered
in overload resolution. */ in overload resolution. */
if (DECL_CONSTRUCTOR_P (fn)) if (DECL_CONSTRUCTOR_P (fn))
{ {
parmnode = TREE_CHAIN (parmnode); parmlist = TREE_CHAIN (parmlist);
argnode = TREE_CHAIN (argnode); arglist = TREE_CHAIN (arglist);
if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn))) if (TYPE_USES_VIRTUAL_BASECLASSES (DECL_CONTEXT (fn)))
{ {
parmnode = TREE_CHAIN (parmnode); parmlist = TREE_CHAIN (parmlist);
argnode = TREE_CHAIN (argnode); arglist = TREE_CHAIN (arglist);
} }
} }
len = list_length (argnode); len = list_length (arglist);
/* 13.3.2 - Viable functions [over.match.viable]
First, to be a viable function, a candidate function shall have enough
parameters to agree in number with the arguments in the list.
We need to check this first; otherwise, checking the ICSes might cause
us to produce an ill-formed template instantiation. */
parmnode = parmlist;
for (i = 0; i < len; ++i)
{
if (parmnode == NULL_TREE || parmnode == void_list_node)
break;
parmnode = TREE_CHAIN (parmnode);
}
if (i < len && parmnode)
viable = 0;
/* Make sure there are default args for the rest of the parms. */
else for (; parmnode && parmnode != void_list_node;
parmnode = TREE_CHAIN (parmnode))
if (! TREE_PURPOSE (parmnode))
{
viable = 0;
break;
}
if (! viable)
goto out;
/* Second, for F to be a viable function, there shall exist for each
argument an implicit conversion sequence that converts that argument
to the corresponding parameter of F. */
parmnode = parmlist;
argnode = arglist;
convs = make_scratch_vec (len); convs = make_scratch_vec (len);
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i)
...@@ -1196,7 +1232,10 @@ add_function_candidate (candidates, fn, arglist, flags) ...@@ -1196,7 +1232,10 @@ add_function_candidate (candidates, fn, arglist, flags)
TREE_VEC_ELT (convs, i) = t; TREE_VEC_ELT (convs, i) = t;
if (! t) if (! t)
break; {
viable = 0;
break;
}
if (ICS_BAD_FLAG (t)) if (ICS_BAD_FLAG (t))
viable = -1; viable = -1;
...@@ -1206,18 +1245,7 @@ add_function_candidate (candidates, fn, arglist, flags) ...@@ -1206,18 +1245,7 @@ add_function_candidate (candidates, fn, arglist, flags)
argnode = TREE_CHAIN (argnode); argnode = TREE_CHAIN (argnode);
} }
if (i < len) out:
viable = 0;
/* Make sure there are default args for the rest of the parms. */
for (; parmnode && parmnode != void_list_node;
parmnode = TREE_CHAIN (parmnode))
if (! TREE_PURPOSE (parmnode))
{
viable = 0;
break;
}
return add_candidate (candidates, fn, convs, viable); return add_candidate (candidates, fn, convs, viable);
} }
......
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