This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH, committed] Fix PR12170 Unifying template templateparameter


Hi

This patch fixes the PR12170.  This is a flaw When deducing parameters
used inside template template parameter.  An example is deducing 'T' and
'TT' in 'TT<T>' against 'X<int>::Z<char>', which should gives 'T'='char' and
'TT'='X<int>::Z'.  We forget to realize that the template arguments of
'Z' has level 2 and therefore is represented as TREE_VEC of TREE_VEC.
This confuses the recursive call to unify to figure out what 'T' is.

Tested on i686-pc-linux-gnu.  Committed to mainline as obvious.

--Kriang

2004-07-19  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/12170
	* pt.c (unify) <BOUND_TEMPLATE_TEMPLATE_PARM case>: Use only
	innermost set of template arguments during deduction.  Simplify.

2004-07-19  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>

	PR c++/12170
	* g++.dg/template/ttp9.C: New test.

diff -cprN gcc-main-save/gcc/cp/pt.c gcc-main-new/gcc/cp/pt.c
*** gcc-main-save/gcc/cp/pt.c	Sat Jul 17 17:27:37 2004
--- gcc-main-new/gcc/cp/pt.c	Sun Jul 18 23:14:04 2004
*************** unify (tree tparms, tree targs, tree par
*** 9650,9656 ****
  	  {
  	    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;
--- 9650,9656 ----
  	  {
  	    tree parmtmpl = TYPE_TI_TEMPLATE (parm);
  	    tree parmvec = TYPE_TI_ARGS (parm);
! 	    tree argvec = INNERMOST_TEMPLATE_ARGS (TYPE_TI_ARGS (arg));
  	    tree argtmplvec
  	      = DECL_INNERMOST_TEMPLATE_PARMS (TYPE_TI_TEMPLATE (arg));
  	    int i;
*************** unify (tree tparms, tree targs, tree par
*** 9673,9681 ****
  
  	    for (i = 0; i < TREE_VEC_LENGTH (parmvec); ++i)
  	      {
! 	        tree t = TREE_VEC_ELT (parmvec, i);
! 
! 	        if (unify (tparms, targs, t, 
  			   TREE_VEC_ELT (argvec, i), 
  			   UNIFY_ALLOW_NONE))
  		  return 1;
--- 9673,9680 ----
  
  	    for (i = 0; i < TREE_VEC_LENGTH (parmvec); ++i)
  	      {
! 	        if (unify (tparms, targs, 
! 			   TREE_VEC_ELT (parmvec, i), 
  			   TREE_VEC_ELT (argvec, i), 
  			   UNIFY_ALLOW_NONE))
  		  return 1;
diff -cprN gcc-main-save/gcc/testsuite/g++.dg/template/ttp9.C gcc-main-new/gcc/testsuite/g++.dg/template/ttp9.C
*** gcc-main-save/gcc/testsuite/g++.dg/template/ttp9.C	Thu Jan  1 07:00:00 1970
--- gcc-main-new/gcc/testsuite/g++.dg/template/ttp9.C	Sun Jul 18 22:48:31 2004
***************
*** 0 ****
--- 1,28 ----
+ // { dg-do compile }
+ 
+ // Origin: David Abrahams <dave@boost-consulting.com>
+ //	   Wolfgang Bangerth <bangerth@ticam.utexas.edu>
+ 
+ // PR c++/12170: Deducing template template parameter from nested
+ // class template.
+ 
+ template <typename> struct W {};
+ 
+ template< template<typename> class F, typename T>
+ int foo(W< F<T> >);
+ 
+ 
+ template<typename T>
+ struct L  {
+     static int const value = sizeof(foo(W<T>()));
+     typedef T type;
+ };
+ 
+ 
+ template <typename>
+ struct Y {
+     template <typename> struct X { typedef int type; };
+     typedef typename L<X<int> >::type type;
+ };
+ 
+ template struct Y<int>;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]