re PR c++/6749 (infinite loop with inheritance of abstract classes)

PR c++/6749
	* pt.c (instantiate_pending_templates): Add int parameter.  Don't
	return anything.
	* cp-tree.h (instantiate_pending_templates): Adjust prototype.
	* decl2.c (finish_file): Adjust call to
	instantiate_pending_templates.

	* g++.dg/template/vtable2.C: New test.

From-SVN: r86054
This commit is contained in:
Kriang Lerdsuwanakij 2004-08-16 14:29:27 +00:00 committed by Kriang Lerdsuwanakij
parent a20f4d83c8
commit 35046a541c
6 changed files with 60 additions and 19 deletions

View File

@ -1,3 +1,12 @@
2004-08-16 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/6749
* pt.c (instantiate_pending_templates): Add int parameter. Don't
return anything.
* cp-tree.h (instantiate_pending_templates): Adjust prototype.
* decl2.c (finish_file): Adjust call to
instantiate_pending_templates.
2004-08-15 Roger Sayle <roger@eyesopen.com>
* call.c (build_vfield_ref, build_call, build_conditional_expr,

View File

@ -3990,7 +3990,7 @@ extern void maybe_process_partial_specialization (tree);
extern void maybe_check_template_type (tree);
extern tree most_specialized_instantiation (tree);
extern void print_candidates (tree);
extern int instantiate_pending_templates (void);
extern void instantiate_pending_templates (int);
extern tree tsubst_default_argument (tree, tree, tree);
extern tree tsubst_copy_and_build (tree, tree, tsubst_flags_t, tree, bool);
extern tree most_general_template (tree);

View File

@ -2721,6 +2721,7 @@ finish_file (void)
size_t i;
location_t locus;
unsigned ssdf_count = 0;
int retries = 0;
locus = input_location;
at_eof = 1;
@ -2772,7 +2773,7 @@ finish_file (void)
/* If there are templates that we've put off instantiating, do
them now. */
instantiate_pending_templates ();
instantiate_pending_templates (retries);
ggc_collect ();
/* Write out virtual tables as required. Note that writing out
@ -2994,6 +2995,8 @@ finish_file (void)
reconsider = true;
if (cgraph_varpool_assemble_pending_decls ())
reconsider = true;
retries++;
}
while (reconsider);

View File

@ -11272,17 +11272,30 @@ out:
}
/* Run through the list of templates that we wish we could
instantiate, and instantiate any we can. */
instantiate, and instantiate any we can. RETRIES is the
number of times we retry pending template instantiation. */
int
instantiate_pending_templates (void)
void
instantiate_pending_templates (int retries)
{
tree *t;
tree last = NULL_TREE;
int instantiated_something = 0;
int reconsider;
location_t saved_loc = input_location;
/* Instantiating templates may trigger vtable generation. This in turn
may require further template instantiations. We place a limit here
to avoid infinite loop. */
if (pending_templates && retries >= max_tinst_depth)
{
cp_error_at ("template instantiation depth exceeds maximum of %d"
" (use -ftemplate-depth-NN to increase the maximum)"
" instantiating `%+D', possibly from virtual table"
" generation",
max_tinst_depth, TREE_VALUE (pending_templates));
return;
}
do
{
reconsider = 0;
@ -11309,11 +11322,8 @@ instantiate_pending_templates (void)
instantiate_decl (fn, /*defer_ok=*/0,
/*undefined_ok=*/0);
if (COMPLETE_TYPE_P (instantiation))
{
instantiated_something = 1;
reconsider = 1;
}
}
if (COMPLETE_TYPE_P (instantiation))
/* If INSTANTIATION has been instantiated, then we don't
@ -11334,11 +11344,8 @@ instantiate_pending_templates (void)
/*defer_ok=*/0,
/*undefined_ok=*/0);
if (DECL_TEMPLATE_INSTANTIATED (instantiation))
{
instantiated_something = 1;
reconsider = 1;
}
}
if (DECL_TEMPLATE_SPECIALIZATION (instantiation)
|| DECL_TEMPLATE_INSTANTIATED (instantiation))
@ -11359,7 +11366,6 @@ instantiate_pending_templates (void)
while (reconsider);
input_location = saved_loc;
return instantiated_something;
}
/* Substitute ARGVEC into T, which is a list of initializers for

View File

@ -1,3 +1,8 @@
2004-08-16 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
PR c++/6749
* g++.dg/template/vtable2.C: New test.
2004-08-14 Richard Henderson <rth@redhat.com>
* gcc.dg/torture/builtin-attr-1.c: Fix scalbln prototype.

View File

@ -0,0 +1,18 @@
// Use a small template instantiation depth to speed up testing
// { dg-options "-ftemplate-depth-5" }
// { dg-do compile }
// Origin: rullo.pat@tiscalinet.it
// Nathanael Nerode <neroden@gcc.gnu.org>
// Wolfgang Bangerth <bangerth@dealii.org>
// PR c++/6749: Infinite loop generating vtable.
template <class T> struct inner {};
template <class T> struct parent {
virtual void f()
{ parent<inner<T> > p; }; // { dg-error "instantiation depth" }
};
template struct parent<int>;