Commit 809c28c8 by Jason Merrill Committed by Jason Merrill

PR c++/71834 - template-id with too few arguments.

	* pt.c (coerce_template_parms): Check fixed_parameter_pack_p.

From-SVN: r258659
parent 058494f9
2018-03-16 Jason Merrill <jason@redhat.com>
PR c++/71834 - template-id with too few arguments.
* pt.c (coerce_template_parms): Check fixed_parameter_pack_p.
2018-03-19 Nathan Sidwell <nathan@acm.org> 2018-03-19 Nathan Sidwell <nathan@acm.org>
PR c++/84835 PR c++/84835
......
...@@ -8235,6 +8235,11 @@ coerce_template_parms (tree parms, ...@@ -8235,6 +8235,11 @@ coerce_template_parms (tree parms,
int variadic_args_p = 0; int variadic_args_p = 0;
int post_variadic_parms = 0; int post_variadic_parms = 0;
/* Adjustment to nparms for fixed parameter packs. */
int fixed_pack_adjust = 0;
int fixed_packs = 0;
int missing = 0;
/* Likewise for parameters with default arguments. */ /* Likewise for parameters with default arguments. */
int default_p = 0; int default_p = 0;
...@@ -8279,6 +8284,7 @@ coerce_template_parms (tree parms, ...@@ -8279,6 +8284,7 @@ coerce_template_parms (tree parms,
|| (TREE_VEC_ELT (parms, nargs) != error_mark_node || (TREE_VEC_ELT (parms, nargs) != error_mark_node
&& !TREE_PURPOSE (TREE_VEC_ELT (parms, nargs)))))) && !TREE_PURPOSE (TREE_VEC_ELT (parms, nargs))))))
{ {
bad_nargs:
if (complain & tf_error) if (complain & tf_error)
{ {
if (variadic_p || default_p) if (variadic_p || default_p)
...@@ -8390,11 +8396,17 @@ coerce_template_parms (tree parms, ...@@ -8390,11 +8396,17 @@ coerce_template_parms (tree parms,
lost++; lost++;
/* We are done with all of the arguments. */ /* We are done with all of the arguments. */
arg_idx = nargs; arg_idx = nargs;
break;
} }
else else
{ {
pack_adjust = TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) - 1; pack_adjust = TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) - 1;
arg_idx += pack_adjust; arg_idx += pack_adjust;
if (fixed_parameter_pack_p (TREE_VALUE (parm)))
{
++fixed_packs;
fixed_pack_adjust += pack_adjust;
}
} }
continue; continue;
...@@ -8452,12 +8464,18 @@ coerce_template_parms (tree parms, ...@@ -8452,12 +8464,18 @@ coerce_template_parms (tree parms,
error ("template argument %d is invalid", arg_idx + 1); error ("template argument %d is invalid", arg_idx + 1);
} }
else if (!arg) else if (!arg)
/* This only occurs if there was an error in the template {
parameter list itself (which we would already have /* This can occur if there was an error in the template
reported) that we are trying to recover from, e.g., a class parameter list itself (which we would already have
template with a parameter list such as reported) that we are trying to recover from, e.g., a class
template<typename..., typename>. */ template with a parameter list such as
++lost; template<typename..., typename> (cpp0x/variadic150.C). */
++lost;
/* This can also happen with a fixed parameter pack (71834). */
if (arg_idx >= nargs)
++missing;
}
else else
arg = convert_template_argument (TREE_VALUE (parm), arg = convert_template_argument (TREE_VALUE (parm),
arg, new_args, complain, arg, new_args, complain,
...@@ -8470,20 +8488,20 @@ coerce_template_parms (tree parms, ...@@ -8470,20 +8488,20 @@ coerce_template_parms (tree parms,
cp_unevaluated_operand = saved_unevaluated_operand; cp_unevaluated_operand = saved_unevaluated_operand;
c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings; c_inhibit_evaluation_warnings = saved_inhibit_evaluation_warnings;
if (variadic_p && arg_idx < nargs) if (missing || arg_idx < nargs - variadic_args_p)
{ {
if (complain & tf_error) /* If we had fixed parameter packs, we didn't know how many arguments we
{ actually needed earlier; now we do. */
error ("wrong number of template arguments " nparms += fixed_pack_adjust;
"(%d, should be %d)", nargs, arg_idx); variadic_p -= fixed_packs;
if (in_decl) goto bad_nargs;
error ("provided for %q+D", in_decl);
}
return error_mark_node;
} }
if (lost) if (lost)
return error_mark_node; {
gcc_assert (!(complain & tf_error) || seen_error ());
return error_mark_node;
}
if (CHECKING_P && !NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_inner_args)) if (CHECKING_P && !NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_inner_args))
SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_inner_args, SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (new_inner_args,
......
// PR c++/71834
// { dg-do compile { target c++11 } }
template < typename ... Ts > struct A
{
template < Ts ..., typename U > struct B {};
};
// should be, e.g.: A < int >::B < 0, int > e;
A < int >::B < 0 > e; // { dg-error "wrong number of template arguments" }
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