pt.c (for_each_template_parm): Don't examine uninstantiated default arguments.
authorMark Mitchell <mark@markmitchell.com>
Fri, 16 Oct 1998 13:24:28 +0000 (13:24 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Fri, 16 Oct 1998 13:24:28 +0000 (13:24 +0000)
* pt.c (for_each_template_parm): Don't examine uninstantiated
default arguments.

From-SVN: r23137

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/g++.old-deja/g++.pt/defarg5.C [new file with mode: 0644]

index 317161bf1cca06c7decf77f403a729d17dee8ef1..4fa45af56638f644dccf72e558d25b0bfe019d5f 100644 (file)
@@ -1,3 +1,8 @@
+1998-10-16  Mark Mitchell  <mark@markmitchell.com>
+
+       * pt.c (for_each_template_parm): Don't examine uninstantiated
+       default arguments.
+
 1998-10-16  Dave Brolley  <brolley@cygnus.com>
 
         * lex.c (real_yylex): Fix unaligned access of wchar_t.
index c3e2d2ebdc24fd37433b5d9a60f1aa24e4314ecf..852634c622a8dc4088f45c5ac807cae6012d23d9 100644 (file)
@@ -3766,10 +3766,29 @@ for_each_template_parm (t, fn, data)
       return for_each_template_parm (TREE_VALUE
                                     (TYPE_TEMPLATE_INFO (t)),
                                     fn, data);
-    case FUNCTION_TYPE:
-      if (for_each_template_parm (TYPE_ARG_TYPES (t), fn, data))
+    case METHOD_TYPE:
+      if (for_each_template_parm (TYPE_METHOD_BASETYPE (t), fn, data))
        return 1;
+      /* Fall through.  */
+
+    case FUNCTION_TYPE:
+      /* Check the parameter types.  Since default arguments are not
+        instantiated until they are needed, the TYPE_ARG_TYPES may
+        contain expressions that involve template parameters.  But,
+        no-one should be looking at them yet.  And, once they're
+        instantiated, they don't contain template parameters, so
+        there's no point in looking at them then, either.  */
+      {
+       tree parm;
+
+       for (parm = TYPE_ARG_TYPES (t); parm; parm = TREE_CHAIN (parm))
+         if (for_each_template_parm (TREE_VALUE (parm), fn, data))
+           return 1;
+      }
+
+      /* Check the return type, too.  */
       return for_each_template_parm (TREE_TYPE (t), fn, data);
+
     case ARRAY_TYPE:
       if (for_each_template_parm (TYPE_DOMAIN (t), fn, data))
        return 1;
@@ -3778,12 +3797,6 @@ for_each_template_parm (t, fn, data)
       if (for_each_template_parm (TYPE_OFFSET_BASETYPE (t), fn, data))
        return 1;
       return for_each_template_parm (TREE_TYPE (t), fn, data);
-    case METHOD_TYPE:
-      if (for_each_template_parm (TYPE_METHOD_BASETYPE (t), fn, data))
-       return 1;
-      if (for_each_template_parm (TYPE_ARG_TYPES (t), fn, data))
-       return 1;
-      return for_each_template_parm (TREE_TYPE (t), fn, data);
 
       /* decl nodes */
     case TYPE_DECL:
diff --git a/gcc/testsuite/g++.old-deja/g++.pt/defarg5.C b/gcc/testsuite/g++.old-deja/g++.pt/defarg5.C
new file mode 100644 (file)
index 0000000..6a68bad
--- /dev/null
@@ -0,0 +1,24 @@
+// Build don't link:
+
+template <int dim>
+class Point {
+  public:
+    Point (Point<dim> &);
+    Point<dim> & operator = (Point<dim> &);
+};
+
+
+
+template <int dim>
+class bar{
+  public:
+    void foo (Point<dim> p = Point<dim>());
+};
+
+
+
+template <>
+void bar<2>::foo (Point<2> p) {
+  const int dim = 2;
+  Point<dim> q = p;
+};