Commit 27fafc8d by Jason Merrill Committed by Jason Merrill

pt.c (determine_specialization): Just return an error_mark_node.

	* pt.c (determine_specialization): Just return an error_mark_node.
	Also print the decl we want in error messages.  If we complain,
	return error_mark_node.
	(tsubst_friend_function): Set lineno and input_filename so
	error messages will be useful.
	(instantiate_template): Just return an error_mark_node.
	* pt.c (print_template_context): Add new argument.
	(maybe_print_template_context): New fn.
	(push_tinst_level): Increment tinst_level_tick.
	(pop_tinst_level): Likewise.
	* errfn.c (cp_thing): Call maybe_print_template_context.  Use
	xrealloc instead of xmalloc.
	* typeck.c (build_unary_op, CONVERT_EXPR): Propagate TREE_CONSTANT.

From-SVN: r19946
parent 911c3b7d
1998-05-22 Jason Merrill <jason@yorick.cygnus.com>
* pt.c (determine_specialization): Just return an error_mark_node.
Also print the decl we want in error messages. If we complain,
return error_mark_node.
(tsubst_friend_function): Set lineno and input_filename so
error messages will be useful.
(instantiate_template): Just return an error_mark_node.
* pt.c (print_template_context): Add new argument.
(maybe_print_template_context): New fn.
(push_tinst_level): Increment tinst_level_tick.
(pop_tinst_level): Likewise.
* errfn.c (cp_thing): Call maybe_print_template_context. Use
xrealloc instead of xmalloc.
* typeck.c (build_unary_op, CONVERT_EXPR): Propagate TREE_CONSTANT.
1998-05-21 Jason Merrill <jason@yorick.cygnus.com> 1998-05-21 Jason Merrill <jason@yorick.cygnus.com>
* pt.c (tsubst_friend_class): Don't call redeclare_class_template * pt.c (tsubst_friend_class): Don't call redeclare_class_template
......
...@@ -72,11 +72,13 @@ cp_thing (errfn, atarg1, format, ap) ...@@ -72,11 +72,13 @@ cp_thing (errfn, atarg1, format, ap)
const char *f; const char *f;
tree atarg = 0; tree atarg = 0;
maybe_print_template_context ();
len = strlen (format) + 1; len = strlen (format) + 1;
if (len > buflen) if (len > buflen)
{ {
buflen = len; buflen = len;
buf = xmalloc (buflen); buf = xrealloc (buf, buflen);
} }
offset = 0; offset = 0;
......
...@@ -756,6 +756,9 @@ determine_specialization (template_id, decl, targs_out, ...@@ -756,6 +756,9 @@ determine_specialization (template_id, decl, targs_out,
*targs_out = NULL_TREE; *targs_out = NULL_TREE;
if (fns == error_mark_node)
return error_mark_node;
/* Check for baselinks. */ /* Check for baselinks. */
if (TREE_CODE (fns) == TREE_LIST) if (TREE_CODE (fns) == TREE_LIST)
fns = TREE_VALUE (fns); fns = TREE_VALUE (fns);
...@@ -823,9 +826,11 @@ determine_specialization (template_id, decl, targs_out, ...@@ -823,9 +826,11 @@ determine_specialization (template_id, decl, targs_out,
{ {
no_match: no_match:
if (complain) if (complain)
cp_error ("`%D' does not match any template declaration", {
template_id); cp_error_at ("template-id `%D' for `%+D' does not match any template declaration",
template_id, decl);
return error_mark_node;
}
return NULL_TREE; return NULL_TREE;
} }
else if (TREE_CHAIN (templates) != NULL_TREE) else if (TREE_CHAIN (templates) != NULL_TREE)
...@@ -833,9 +838,10 @@ determine_specialization (template_id, decl, targs_out, ...@@ -833,9 +838,10 @@ determine_specialization (template_id, decl, targs_out,
ambiguous: ambiguous:
if (complain) if (complain)
{ {
cp_error ("ambiguous template specialization `%D'", cp_error_at ("ambiguous template specialization `%D' for `%+D'",
template_id); template_id, decl);
print_candidates (templates); print_candidates (templates);
return error_mark_node;
} }
return NULL_TREE; return NULL_TREE;
} }
...@@ -3313,24 +3319,46 @@ uses_template_parms (t) ...@@ -3313,24 +3319,46 @@ uses_template_parms (t)
return for_each_template_parm (t, 0, 0); return for_each_template_parm (t, 0, 0);
} }
static struct tinst_level *current_tinst_level = 0; static struct tinst_level *current_tinst_level;
static struct tinst_level *free_tinst_level = 0; static struct tinst_level *free_tinst_level;
static int tinst_depth = 0; static int tinst_depth;
extern int max_tinst_depth; extern int max_tinst_depth;
#ifdef GATHER_STATISTICS #ifdef GATHER_STATISTICS
int depth_reached = 0; int depth_reached;
#endif #endif
int tinst_level_tick;
int last_template_error_tick;
/* Print out all the template instantiations that we are currently /* Print out all the template instantiations that we are currently
working on. */ working on. If ERR, we are being called from cp_thing, so do
the right thing for an error message. */
void static void
print_template_context () print_template_context (err)
int err;
{ {
struct tinst_level *p = current_tinst_level; struct tinst_level *p = current_tinst_level;
int line = lineno; int line = lineno;
char *file = input_filename; char *file = input_filename;
if (err)
{
if (current_function_decl == p->decl)
/* Avoid redundancy with the the "In function" line. */;
else if (current_function_decl == NULL_TREE)
cp_error ("In instantiation of `%D':", p->decl);
else
my_friendly_abort (980521);
if (p)
{
lineno = p->line;
input_filename = p->file;
p = p->next;
}
}
next:
for (; p; p = p->next) for (; p; p = p->next)
{ {
cp_error (" instantiated from `%D'", p->decl); cp_error (" instantiated from `%D'", p->decl);
...@@ -3343,6 +3371,19 @@ print_template_context () ...@@ -3343,6 +3371,19 @@ print_template_context ()
input_filename = file; input_filename = file;
} }
/* Called from cp_thing to print the template context for an error. */
void
maybe_print_template_context ()
{
if (last_template_error_tick == tinst_level_tick
|| current_tinst_level == 0)
return;
last_template_error_tick = tinst_level_tick;
print_template_context (1);
}
static int static int
push_tinst_level (d) push_tinst_level (d)
tree d; tree d;
...@@ -3362,7 +3403,7 @@ push_tinst_level (d) ...@@ -3362,7 +3403,7 @@ push_tinst_level (d)
error (" (use -ftemplate-depth-NN to increase the maximum)"); error (" (use -ftemplate-depth-NN to increase the maximum)");
cp_error (" instantiating `%D'", d); cp_error (" instantiating `%D'", d);
print_template_context (); print_template_context (0);
return 0; return 0;
} }
...@@ -3387,6 +3428,7 @@ push_tinst_level (d) ...@@ -3387,6 +3428,7 @@ push_tinst_level (d)
depth_reached = tinst_depth; depth_reached = tinst_depth;
#endif #endif
++tinst_level_tick;
return 1; return 1;
} }
...@@ -3399,6 +3441,7 @@ pop_tinst_level () ...@@ -3399,6 +3441,7 @@ pop_tinst_level ()
old->next = free_tinst_level; old->next = free_tinst_level;
free_tinst_level = old; free_tinst_level = old;
--tinst_depth; --tinst_depth;
++tinst_level_tick;
} }
struct tinst_level * struct tinst_level *
...@@ -3423,7 +3466,12 @@ tsubst_friend_function (decl, args) ...@@ -3423,7 +3466,12 @@ tsubst_friend_function (decl, args)
tree args; tree args;
{ {
tree new_friend; tree new_friend;
int line = lineno;
char *file = input_filename;
lineno = DECL_SOURCE_LINE (decl);
input_filename = DECL_SOURCE_FILE (decl);
if (TREE_CODE (decl) == FUNCTION_DECL if (TREE_CODE (decl) == FUNCTION_DECL
&& DECL_TEMPLATE_INSTANTIATION (decl) && DECL_TEMPLATE_INSTANTIATION (decl)
&& TREE_CODE (DECL_TI_TEMPLATE (decl)) != TEMPLATE_DECL) && TREE_CODE (DECL_TI_TEMPLATE (decl)) != TEMPLATE_DECL)
...@@ -3458,10 +3506,11 @@ tsubst_friend_function (decl, args) ...@@ -3458,10 +3506,11 @@ tsubst_friend_function (decl, args)
new_friend, new_friend,
&new_args, &new_args,
0, 1); 0, 1);
return instantiate_template (tmpl, new_args); new_friend = instantiate_template (tmpl, new_args);
goto done;
} }
else else
new_friend = tsubst (decl, args, NULL_TREE); new_friend = tsubst (decl, args, NULL_TREE);
/* The new_friend will look like an instantiation, to the /* The new_friend will look like an instantiation, to the
compiler, but is not an instantiation from the point of view of compiler, but is not an instantiation from the point of view of
...@@ -3497,6 +3546,9 @@ tsubst_friend_function (decl, args) ...@@ -3497,6 +3546,9 @@ tsubst_friend_function (decl, args)
new_friend = fn; new_friend = fn;
} }
done:
lineno = line;
input_filename = file;
return new_friend; return new_friend;
} }
...@@ -5516,6 +5568,9 @@ instantiate_template (tmpl, targ_ptr) ...@@ -5516,6 +5568,9 @@ instantiate_template (tmpl, targ_ptr)
struct obstack *old_fmp_obstack; struct obstack *old_fmp_obstack;
extern struct obstack *function_maybepermanent_obstack; extern struct obstack *function_maybepermanent_obstack;
if (tmpl == error_mark_node)
return error_mark_node;
my_friendly_assert (TREE_CODE (tmpl) == TEMPLATE_DECL, 283); my_friendly_assert (TREE_CODE (tmpl) == TEMPLATE_DECL, 283);
/* FIXME this won't work with member templates; we only have one level /* FIXME this won't work with member templates; we only have one level
......
...@@ -4259,6 +4259,7 @@ build_unary_op (code, xarg, noconvert) ...@@ -4259,6 +4259,7 @@ build_unary_op (code, xarg, noconvert)
if (!noconvert) if (!noconvert)
arg = default_conversion (arg); arg = default_conversion (arg);
arg = build1 (NON_LVALUE_EXPR, TREE_TYPE (arg), arg); arg = build1 (NON_LVALUE_EXPR, TREE_TYPE (arg), arg);
TREE_CONSTANT (arg) = TREE_CONSTANT (TREE_OPERAND (arg, 0));
} }
break; break;
......
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