re PR c++/3870 (gcc 3.0 bogus error specializing a template function)
authorJason Merrill <jason@redhat.com>
Mon, 18 Mar 2002 14:36:19 +0000 (09:36 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 18 Mar 2002 14:36:19 +0000 (09:36 -0500)
        PR c++/3870
        * cp-tree.h (struct saved_scope): Add last_parms field.
        * decl.c (maybe_push_to_top_level): Save last_function_parms.
        (pop_from_top_level): Restore it.

From-SVN: r50970

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/testsuite/g++.dg/template/spec3.C [new file with mode: 0644]

index 94682bc..c5b30b7 100644 (file)
@@ -1,5 +1,10 @@
 2002-03-18  Jason Merrill  <jason@redhat.com>
 
+       PR c++/3870
+       * cp-tree.h (struct saved_scope): Add last_parms field.
+       * decl.c (maybe_push_to_top_level): Save last_function_parms.
+       (pop_from_top_level): Restore it.
+
        PR c++/4377
        * mangle.c (write_expression): Strip NOP_EXPRs sooner.  Also strip
        NON_LVALUE_EXPRs.
index fac6a9d..6da6811 100644 (file)
@@ -731,6 +731,7 @@ struct saved_scope
   tree x_saved_tree;
   tree incomplete;
   tree lookups;
+  tree last_parms;
 
   HOST_WIDE_INT x_processing_template_decl;
   int x_processing_specialization;
index 30351c9..fcc87fe 100644 (file)
@@ -2501,6 +2501,7 @@ maybe_push_to_top_level (pseudo)
   s->bindings = b;
   s->need_pop_function_context = need_pop;
   s->function_decl = current_function_decl;
+  s->last_parms = last_function_parms;
 
   scope_chain = s;
   current_function_decl = NULL_TREE;
@@ -2542,6 +2543,7 @@ pop_from_top_level ()
   if (s->need_pop_function_context)
     pop_function_context_from (NULL_TREE);
   current_function_decl = s->function_decl;
+  last_function_parms = s->last_parms;
 
   free (s);
 }
diff --git a/gcc/testsuite/g++.dg/template/spec3.C b/gcc/testsuite/g++.dg/template/spec3.C
new file mode 100644 (file)
index 0000000..d3fa401
--- /dev/null
@@ -0,0 +1,16 @@
+// PR c++/3870
+// Test that performing a type instantiation in order to match up a
+// specialization doesn't clobber last_function_parms.
+
+template <class T>
+struct A { typedef int I; };
+
+template <class T>
+inline typename T::I
+foo (typename T::I, const T*);
+
+template <>
+int foo (int i, const A<long>*)
+{
+    return i + 1;
+}