This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Partial ordering bug with template template parm
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++ PATCH] Partial ordering bug with template template parm
- From: Kriang Lerdsuwanakij <lerdsuwa at scf dot usc dot edu>
- Date: Mon, 25 Sep 2000 18:03:06 -0700 (PDT)
Hi,
I discovered a bug when unifying two template template parameters
bound with arguments. unify rejected all such cases. This leads
to incorrect function template partial ordering. A test case is
povided below. There should be no ambiguity deciding g() in both
cases. The attached patch corrects this.
--Kriang
ChangeLog:
2000-09-25 Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
* pt.c (unify): Handle when both ARG and PARM are
BOUND_TEMPLATE_TEMPLATE_PARM.
diff -cprN gcc-old/cp/pt.c gcc/cp/pt.c
*** gcc-old/cp/pt.c Mon Sep 25 17:49:11 2000
--- gcc/cp/pt.c Mon Sep 25 17:48:06 2000
*************** unify (tparms, targs, parm, arg, strict)
*** 8323,8338 ****
if (TREE_CODE (parm) == BOUND_TEMPLATE_TEMPLATE_PARM)
{
! /* ARG must be constructed from a template class. */
! if (TREE_CODE (arg) != RECORD_TYPE || !CLASSTYPE_TEMPLATE_INFO (arg))
return 1;
{
tree parmtmpl = TYPE_TI_TEMPLATE (parm);
tree parmvec = TYPE_TI_ARGS (parm);
! tree argvec = CLASSTYPE_TI_ARGS (arg);
tree argtmplvec
! = DECL_INNERMOST_TEMPLATE_PARMS (CLASSTYPE_TI_TEMPLATE (arg));
int i;
/* The parameter and argument roles have to be switched here
--- 8323,8340 ----
if (TREE_CODE (parm) == BOUND_TEMPLATE_TEMPLATE_PARM)
{
! /* ARG must be constructed from a template class or a template
! template parameter. */
! if (TREE_CODE (arg) != BOUND_TEMPLATE_TEMPLATE_PARM
! && (TREE_CODE (arg) != RECORD_TYPE || !CLASSTYPE_TEMPLATE_INFO (arg)))
return 1;
{
tree parmtmpl = TYPE_TI_TEMPLATE (parm);
tree parmvec = TYPE_TI_ARGS (parm);
! tree argvec = TYPE_TI_ARGS (arg);
tree argtmplvec
! = DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (arg));
int i;
/* The parameter and argument roles have to be switched here
*************** unify (tparms, targs, parm, arg, strict)
*** 8361,8367 ****
return 1;
}
}
! arg = CLASSTYPE_TI_TEMPLATE (arg);
/* Fall through to deduce template name. */
}
--- 8363,8369 ----
return 1;
}
}
! arg = TYPE_TI_TEMPLATE (arg);
/* Fall through to deduce template name. */
}
diff -cprN gcc-old/testsuite/g++.old-deja/g++.pt/ttp65.C gcc/testsuite/g++.old-deja/g++.pt/ttp65.C
*** gcc-old/testsuite/g++.old-deja/g++.pt/ttp65.C Wed Dec 31 16:00:00 1969
--- gcc/testsuite/g++.old-deja/g++.pt/ttp65.C Mon Sep 25 17:48:28 2000
***************
*** 0 ****
--- 1,38 ----
+ // Build don't link:
+
+ // Copyright (C) 2000 Free Software Foundation
+ // Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
+
+ // Bug: We used reject template unification of two bound template template
+ // parameters.
+
+ template <class T, class U=int> class C
+ {
+ };
+
+ template <class T, class U> void f(C<T,U> c)
+ {
+ }
+
+ template <class T> void f(C<T> c)
+ {
+ }
+
+ template <template<class,class=int> class C, class T, class U>
+ void g(C<T,U> c)
+ {
+ }
+
+ template <template<class,class=int> class C, class T> void g(C<T> c)
+ {
+ }
+
+ int main()
+ {
+ C<int,char> c1;
+ f(c1);
+ g(c1);
+ C<int,int> c2;
+ f(c2);
+ g(c2);
+ }