This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH: PR 27640


This patch fixes PR c++/27640, an ICE-on-valid regression.  The
proximate cause was that we were failing to add the in-charge and VTT
parameters to member template constructors if they were instantiated
from within a template function (as part of two-phase name lookup).
The fix is to note that when actually producing a specialization we
are never PROCESSING_TEMPLATE_DECL.

Tested on x86_64-unknown-linux-gnu, applied on the mainline.  I will
apply to 4.1 as soon as testing completes.

--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

2006-06-15  Mark Mitchell  <mark@codesourcery.com>

	PR c++/27640
	* pt.c (instantiate_template): Set processing_template_decl to
	zero while performing substitutions.

2006-06-15  Mark Mitchell  <mark@codesourcery.com>

	PR c++/27640
	* g++.dg/template/ctor7.C: New test.

Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 114665)
+++ gcc/cp/pt.c	(working copy)
@@ -9233,6 +9233,7 @@ instantiate_template (tree tmpl, tree ta
   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 ta
      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;
 
Index: gcc/testsuite/g++.dg/template/ctor7.C
===================================================================
--- gcc/testsuite/g++.dg/template/ctor7.C	(revision 0)
+++ gcc/testsuite/g++.dg/template/ctor7.C	(revision 0)
@@ -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);
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]