This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH]: Incomplete explicit args
Mark Mitchell wrote:
However, if you, Nathan, and the standard all think otherwise, I guess
that's OK with me...
Nathan, I agree that, given this interpretation, the thing to do is to
build a new SCOPE_REF in tsubst_qualified_id, and pass it back.
that doesn't cut it. callers of tsubst_qualified_id expect a non-dependent
expression back (because they feed it to things like build_x_binary_op).
And, in this case processing_template_decl will be false, so it all breaks.
This patch increments processing_template_decl when we're tsubsting
an incomplete explict arg list.
booted & tested on i686-pc-linux-gnu, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
The voices in my head said this was stupid too
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2003-07-30 Nathan Sidwell <nathan@codesourcery.com>
* pt.c (coerce_template_parms): Refactor.
(fn_type_unification): Increment processing_template_decl when
tsubsting an incomplete set of explicit args.
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.742
diff -c -3 -p -r1.742 pt.c
*** cp/pt.c 29 Jul 2003 11:16:48 -0000 1.742
--- cp/pt.c 30 Jul 2003 16:38:41 -0000
*************** coerce_template_parms (tree parms,
*** 3640,3663 ****
}
else if (i < nargs)
arg = TREE_VEC_ELT (inner_args, i);
! else
! /* If no template argument was supplied, look for a default
! value. */
arg = tsubst_template_arg (TREE_PURPOSE (parm), new_args,
complain, in_decl);
!
! /* Now, convert the Ith argument, as necessary. */
! if (arg == NULL_TREE)
! /* We're out of arguments. */
! {
! my_friendly_assert (!require_all_arguments, 0);
! break;
! }
! else if (arg == error_mark_node)
! {
! error ("template argument %d is invalid", i + 1);
! arg = error_mark_node;
! }
else
arg = convert_template_argument (TREE_VALUE (parm),
arg, new_args, complain, i,
--- 3639,3654 ----
}
else if (i < nargs)
arg = TREE_VEC_ELT (inner_args, i);
! else if (require_all_arguments)
! /* There must be a default arg in this case. */
arg = tsubst_template_arg (TREE_PURPOSE (parm), new_args,
complain, in_decl);
! else
! break;
!
! my_friendly_assert (arg, 20030727);
! if (arg == error_mark_node)
! error ("template argument %d is invalid", i + 1);
else
arg = convert_template_argument (TREE_VALUE (parm),
arg, new_args, complain, i,
*************** fn_type_unification (tree fn,
*** 8589,8594 ****
--- 8572,8578 ----
template results in an invalid type, type deduction fails. */
int i;
tree converted_args;
+ bool incomplete;
converted_args
= (coerce_template_parms (DECL_INNERMOST_TEMPLATE_PARMS (fn),
*************** fn_type_unification (tree fn,
*** 8597,8608 ****
if (converted_args == error_mark_node)
return 1;
fntype = tsubst (fntype, converted_args, tf_none, NULL_TREE);
if (fntype == error_mark_node)
return 1;
/* Place the explicitly specified arguments in TARGS. */
! for (i = 0; i < TREE_VEC_LENGTH (targs); i++)
TREE_VEC_ELT (targs, i) = TREE_VEC_ELT (converted_args, i);
}
--- 8581,8602 ----
if (converted_args == error_mark_node)
return 1;
+ /* Substitute the explicit args into the function type. This is
+ necessary so that, for instance, explicitly declared function
+ arguments can match null pointed constants. If we were given
+ an incomplete set of explicit args, we must not do semantic
+ processing during substitution as we could create partial
+ instantiations. */
+ incomplete = NUM_TMPL_ARGS (explicit_targs) != NUM_TMPL_ARGS (targs);
+ processing_template_decl += incomplete;
fntype = tsubst (fntype, converted_args, tf_none, NULL_TREE);
+ processing_template_decl -= incomplete;
+
if (fntype == error_mark_node)
return 1;
/* Place the explicitly specified arguments in TARGS. */
! for (i = NUM_TMPL_ARGS (converted_args); i--;)
TREE_VEC_ELT (targs, i) = TREE_VEC_ELT (converted_args, i);
}