Commit 37457866 by Jason Merrill Committed by Jason Merrill

re PR c++/49785 ([C++0x] ICE in coerce_template_parms)

	PR c++/49785
	* pt.c (coerce_template_parms): Handle non-pack after pack.

From-SVN: r176472
parent 394d3a2e
2011-07-19 Jason Merrill <jason@redhat.com>
PR c++/49785
* pt.c (coerce_template_parms): Handle non-pack after pack.
2011-07-19 Richard Guenther <rguenther@suse.de> 2011-07-19 Richard Guenther <rguenther@suse.de>
* call.c (build_special_member_call): Use fold_build_pointer_plus. * call.c (build_special_member_call): Use fold_build_pointer_plus.
......
...@@ -6537,6 +6537,7 @@ coerce_template_parms (tree parms, ...@@ -6537,6 +6537,7 @@ coerce_template_parms (tree parms,
subtract it from nparms to get the number of non-variadic subtract it from nparms to get the number of non-variadic
parameters. */ parameters. */
int variadic_p = 0; int variadic_p = 0;
int post_variadic_parms = 0;
if (args == error_mark_node) if (args == error_mark_node)
return error_mark_node; return error_mark_node;
...@@ -6547,19 +6548,22 @@ coerce_template_parms (tree parms, ...@@ -6547,19 +6548,22 @@ coerce_template_parms (tree parms,
for (parm_idx = 0; parm_idx < nparms; ++parm_idx) for (parm_idx = 0; parm_idx < nparms; ++parm_idx)
{ {
tree tparm = TREE_VALUE (TREE_VEC_ELT (parms, parm_idx)); tree tparm = TREE_VALUE (TREE_VEC_ELT (parms, parm_idx));
if (variadic_p)
++post_variadic_parms;
if (template_parameter_pack_p (tparm)) if (template_parameter_pack_p (tparm))
++variadic_p; ++variadic_p;
} }
inner_args = INNERMOST_TEMPLATE_ARGS (args); inner_args = INNERMOST_TEMPLATE_ARGS (args);
/* If there are 0 or 1 parameter packs, we need to expand any argument /* If there are no parameters that follow a parameter pack, we need to
packs so that we can deduce a parameter pack from some non-packed args expand any argument packs so that we can deduce a parameter pack from
followed by an argument pack, as in variadic85.C. If there are more some non-packed args followed by an argument pack, as in variadic85.C.
than that, we need to leave argument packs intact so the arguments are If there are such parameters, we need to leave argument packs intact
assigned to the right parameter packs. This should only happen when so the arguments are assigned properly. This can happen when dealing
dealing with a nested class inside a partial specialization of a class with a nested class inside a partial specialization of a class
template, as in variadic92.C. */ template, as in variadic92.C, or when deducing a template parameter pack
if (variadic_p <= 1) from a sub-declarator, as in variadic114.C. */
if (!post_variadic_parms)
inner_args = expand_template_argument_pack (inner_args); inner_args = expand_template_argument_pack (inner_args);
nargs = inner_args ? NUM_TMPL_ARGS (inner_args) : 0; nargs = inner_args ? NUM_TMPL_ARGS (inner_args) : 0;
...@@ -6574,7 +6578,7 @@ coerce_template_parms (tree parms, ...@@ -6574,7 +6578,7 @@ coerce_template_parms (tree parms,
{ {
if (variadic_p) if (variadic_p)
{ {
--nparms; nparms -= variadic_p;
error ("wrong number of template arguments " error ("wrong number of template arguments "
"(%d, should be %d or more)", nargs, nparms); "(%d, should be %d or more)", nargs, nparms);
} }
......
2011-07-19 Jason Merrill <jason@redhat.com>
PR c++/49785
* g++.dg/cpp0x/variadic114.C: New.
2011-07-19 Tobias Burnus <burnus@net-b.de> 2011-07-19 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/coarray_args_1.f90: New. * gfortran.dg/coarray_args_1.f90: New.
......
// PR c++/49785
// { dg-options -std=c++0x }
template <typename, typename ...> struct B { };
template <typename> class A;
template <typename R, typename ... S>
struct A <R (S ...)> : public B <R, S ...>
{
struct C {};
template <typename D> A (D, C = C ()) { }
R operator () (...);
};
template <typename R, typename ... S, typename T>
auto operator >> (A <R (S ...)>, T)->A <R (S ...)>
{
[]() {};
}
int
main ()
{
A <int (int, int)> a = [](int, int) {};
auto b = []{};
(a >> b) (3, 5);
}
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