Commit e1a5ccf7 by Jason Merrill Committed by Jason Merrill

pt.c (push_template_decl_real): Generalize check for incorrect number of template parms.

	* pt.c (push_template_decl_real): Generalize check for incorrect
	number of template parms.

From-SVN: r23422
parent 1d194eae
1998-10-29 Jason Merrill <jason@yorick.cygnus.com>
* pt.c (push_template_decl_real): Generalize check for incorrect
number of template parms.
1998-10-29 Richard Henderson <rth@cygnus.com> 1998-10-29 Richard Henderson <rth@cygnus.com>
* Makefile.in (cc1plus): Put CXX_OBJS, and thence @extra_cxx_objs@, * Makefile.in (cc1plus): Put CXX_OBJS, and thence @extra_cxx_objs@,
......
...@@ -2166,8 +2166,8 @@ push_template_decl_real (decl, is_friend) ...@@ -2166,8 +2166,8 @@ push_template_decl_real (decl, is_friend)
} }
else else
{ {
tree t; tree a, t, current, parms;
tree a; int mem, i;
if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctx)) if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
cp_error ("must specialize `%#T' before defining member `%#D'", cp_error ("must specialize `%#T' before defining member `%#D'",
...@@ -2193,9 +2193,8 @@ push_template_decl_real (decl, is_friend) ...@@ -2193,9 +2193,8 @@ push_template_decl_real (decl, is_friend)
else else
tmpl = DECL_TI_TEMPLATE (decl); tmpl = DECL_TI_TEMPLATE (decl);
if (is_member_template (tmpl) || is_member_template_class (tmpl)) if (is_member_template (tmpl)
{ && DECL_FUNCTION_TEMPLATE_P (tmpl)
if (DECL_FUNCTION_TEMPLATE_P (tmpl)
&& DECL_TEMPLATE_INFO (decl) && DECL_TI_ARGS (decl) && DECL_TEMPLATE_INFO (decl) && DECL_TI_ARGS (decl)
&& DECL_TEMPLATE_SPECIALIZATION (decl)) && DECL_TEMPLATE_SPECIALIZATION (decl))
{ {
...@@ -2221,46 +2220,40 @@ push_template_decl_real (decl, is_friend) ...@@ -2221,46 +2220,40 @@ push_template_decl_real (decl, is_friend)
return decl; return decl;
} }
a = innermost_args (args); /* Make sure the template headers we got make sense. */
t = DECL_INNERMOST_TEMPLATE_PARMS (tmpl);
if (TREE_VEC_LENGTH (t) != TREE_VEC_LENGTH (a)) mem = (is_member_template (tmpl) || is_member_template_class (tmpl));
parms = DECL_TEMPLATE_PARMS (tmpl);
i = TMPL_PARMS_DEPTH (parms);
if (TMPL_ARGS_DEPTH (args) != i)
{ {
cp_error ("got %d template parameters for `%#D'", cp_error ("expected %d levels of template parms for `%#D', got %d",
TREE_VEC_LENGTH (a), decl); i, decl, TMPL_ARGS_DEPTH (args));
cp_error (" but %d required", TREE_VEC_LENGTH (t));
} }
if (TMPL_ARGS_DEPTH (args) > 1)
/* Get the template parameters for the enclosing template
class. */
a = TMPL_ARGS_LEVEL (args, TMPL_ARGS_DEPTH (args) - 1);
else else
a = NULL_TREE; for (current = decl; i > 0; --i, parms = TREE_CHAIN (parms))
}
else
a = innermost_args (args);
t = NULL_TREE;
if (CLASSTYPE_TEMPLATE_SPECIALIZATION (ctx))
{ {
/* When processing an inline member template of a a = TMPL_ARGS_LEVEL (args, i);
specialized class, there is no CLASSTYPE_TI_SPEC_INFO. */ t = INNERMOST_TEMPLATE_PARMS (parms);
if (CLASSTYPE_TI_SPEC_INFO (ctx))
t = TREE_VALUE (CLASSTYPE_TI_SPEC_INFO (ctx));
}
else if (CLASSTYPE_TEMPLATE_INFO (ctx))
t = DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (ctx));
/* There should be template arguments if and only if there is a
template class. */
my_friendly_assert((a != NULL_TREE) == (t != NULL_TREE), 0);
if (t != NULL_TREE if (TREE_VEC_LENGTH (t) != TREE_VEC_LENGTH (a))
&& TREE_VEC_LENGTH (t) != TREE_VEC_LENGTH (a))
{ {
if (current == decl)
cp_error ("got %d template parameters for `%#D'", cp_error ("got %d template parameters for `%#D'",
TREE_VEC_LENGTH (a), decl); TREE_VEC_LENGTH (a), decl);
cp_error (" but `%#T' has %d", ctx, TREE_VEC_LENGTH (t)); else
cp_error ("got %d template parameters for `%#T'",
TREE_VEC_LENGTH (a), current);
cp_error (" but %d required", TREE_VEC_LENGTH (t));
}
/* Perhaps we should also check that the parms are used in the
appropriate qualifying scopes in the declarator? */
if (current == decl)
current = ctx;
else
current = TYPE_CONTEXT (current);
} }
} }
......
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