From a95799ec5fe4e00d99fc1545ff0ea64d10e7e0b9 Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Fri, 16 Jun 2006 02:09:10 +0000 Subject: [PATCH] re PR c++/27640 (segfault, related to constructor instantiation and virtual base case and templates and new operator) PR c++/27640 * pt.c (instantiate_template): Set processing_template_decl to zero while performing substitutions. PR c++/27640 * g++.dg/template/ctor7.C: New test. From-SVN: r114701 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/pt.c | 11 ++++++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/ctor7.C | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/ctor7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 78e4ed861c8..f80d362db88 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2006-06-15 Mark Mitchell + + PR c++/27640 + * pt.c (instantiate_template): Set processing_template_decl to + zero while performing substitutions. + 2006-06-14 Mark Mitchell PR c++/27665 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0cc93fdbb11..d25ea79fae8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9233,6 +9233,7 @@ instantiate_template (tree tmpl, tree targ_ptr, tsubst_flags_t complain) tree fndecl; tree gen_tmpl; tree spec; + HOST_WIDE_INT saved_processing_template_decl; if (tmpl == error_mark_node) return error_mark_node; @@ -9292,9 +9293,17 @@ instantiate_template (tree tmpl, tree targ_ptr, tsubst_flags_t complain) deferring all checks until we have the FUNCTION_DECL. */ push_deferring_access_checks (dk_deferred); - /* Substitute template parameters. */ + /* Although PROCESSING_TEMPLATE_DECL may be true at this point + (because, for example, we have encountered a non-dependent + function call in the body of a template function must determine + which of several overloaded functions will be called), within the + instantiation itself we are not processing a template. */ + saved_processing_template_decl = processing_template_decl; + processing_template_decl = 0; + /* Substitute template parameters to obtain the specialization. */ fndecl = tsubst (DECL_TEMPLATE_RESULT (gen_tmpl), targ_ptr, complain, gen_tmpl); + processing_template_decl = saved_processing_template_decl; if (fndecl == error_mark_node) return error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 25fd9f9dd62..9f056c38cd5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-06-15 Mark Mitchell + + PR c++/27640 + * g++.dg/template/ctor7.C: New test. + 2006-06-15 Janis Johnson * gcc.dg/vmx/pr27842.c: Remove dg-do directive; use default. diff --git a/gcc/testsuite/g++.dg/template/ctor7.C b/gcc/testsuite/g++.dg/template/ctor7.C new file mode 100644 index 00000000000..ee65172fe75 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ctor7.C @@ -0,0 +1,19 @@ +// PR c++/27640 + +template < class T > struct refcounted : +virtual T +{ + template < class A1 > refcounted (const A1 & a1) : T () { } +}; +struct nfsserv {}; +template < class T > +void +sfsserver_cache_alloc (int *ns) +{ + new refcounted < nfsserv > (*ns); +} +void +usage () +{ + sfsserver_cache_alloc < int > ( 0); +} -- 2.30.2