C++ PATCH: template unification bug

Kriang Lerdsuwanakij lerdsuwa@scf-fs.usc.edu
Mon Jan 11 20:16:00 GMT 1999


Hi

The following patch fixes the template argument unification bug
reported by Bruce Eckel at

http://www.cygnus.com/ml/egcs-bugs/1999-Jan/0210.html

The bug was due to my misinterpretation of the standard
when it was first implemented.

--Kriang



        * pt.c (unify): Remove restrictions on deduction of argument
        of template template parameters.


diff -rpNu gcc-old/cp/pt.c gcc/cp/pt.c
--- gcc-old/cp/pt.c     Mon Jan 11 19:46:47 1999
+++ gcc/cp/pt.c Mon Jan 11 19:45:43 1999
@@ -7441,16 +7441,14 @@ unify (tparms, targs, parm, arg, strict,
                    == error_mark_node)
                  return 1;
          
-               /* Deduce arguments T, i from TT<T> or TT<i>.  */
+               /* Deduce arguments T, i from TT<T> or TT<i>.  
+                  We check each element of PARMVEC and ARGVEC individually
+                  rather than the whole TREE_VEC since they can have
+                  different number of elements.  */
+
                for (i = 0; i < TREE_VEC_LENGTH (parmvec); ++i)
                  {
                    tree t = TREE_VEC_ELT (parmvec, i);
-                   if (TREE_CODE (t) != TEMPLATE_TYPE_PARM
-                       && TREE_CODE (t) != TEMPLATE_TEMPLATE_PARM
-                       && TREE_CODE (t) != TEMPLATE_PARM_INDEX)
-                     continue;
-
-                   /* This argument can be deduced.  */
 
                    if (unify (tparms, targs, t, 
                               TREE_VEC_ELT (argvec, i), 
diff -rpNu gcc-old/testsuite/g++.old-deja/g++.pt/ttp54.C gcc/testsuite/g++.old-deja/g++.pt/ttp54.C
--- gcc-old/testsuite/g++.old-deja/g++.pt/ttp54.C       Wed Dec 31 16:00:00 1969
+++ gcc/testsuite/g++.old-deja/g++.pt/ttp54.C   Mon Jan 11 19:46:08 1999
@@ -0,0 +1,20 @@
+// Build don't link:
+
+// Reported by Bruce Eckel <Bruce@EckelObjects.com>
+
+// [temp.deduct.type]
+// Make sure we treat <T> in the construct TT<T> as any type containing T.
+
+template <class T> class C
+{
+};
+
+template <class T, template <class> class TT> void f (TT<T *> &t)
+{
+}
+
+int main ()
+{
+       C<char *> c;
+       f(c);
+}



More information about the Gcc-patches mailing list