PR c++/27640
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 16 Jun 2006 02:09:10 +0000 (02:09 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 16 Jun 2006 02:09:10 +0000 (02:09 +0000)
* pt.c (instantiate_template): Set processing_template_decl to
zero while performing substitutions.
PR c++/27640
* g++.dg/template/ctor7.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114701 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/ctor7.C [new file with mode: 0644]

index 78e4ed8..f80d362 100644 (file)
@@ -1,3 +1,9 @@
+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-14  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/27665
index 0cc93fd..d25ea79 100644 (file)
@@ -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;
 
index 25fd9f9..9f056c3 100644 (file)
@@ -1,3 +1,8 @@
+2006-06-15  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/27640
+       * g++.dg/template/ctor7.C: New test.
+
 2006-06-15  Janis Johnson  <janis187@us.ibm.com>
 
        * 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 (file)
index 0000000..ee65172
--- /dev/null
@@ -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);
+}