Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > b5e52bbfb4bb11a6cbed452927fba979 > files > 37

gcc-4.1.2-50.el5.src.rpm

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

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

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

--- gcc/cp/pt.c	(revision 114700)
+++ gcc/cp/pt.c	(revision 114701)
@@ -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;
 
--- gcc/testsuite/g++.dg/template/ctor7.C	(revision 0)
+++ gcc/testsuite/g++.dg/template/ctor7.C	(revision 114701)
@@ -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);
+}
--- gcc/testsuite/g++.dg/template/ctor99.C	2009-03-16 12:39:23.737002275 +0100
+++ gcc/testsuite/g++.dg/template/ctor99.C	2009-03-17 18:09:25.000000000 +0100
@@ -0,0 +1,23 @@
+// { dg-do compile }
+// { dg-options "-fabi-version=1" }
+
+template<int N>
+int f (char (&)[N])
+{
+  return N;
+}
+
+char str[12];
+
+struct S
+{
+  int i;
+  template <typename U>
+  S (U) : i (f (str)) {}
+};
+
+int
+main ()
+{
+  S s (1);
+}