PATCH template template parameter & partial specialization

Kriang Lerdsuwanakij lerdsuwa@scf-fs.usc.edu
Thu Jun 25 22:39:00 GMT 1998


Hi

The following patch fixes the bug reported earlier in egcs-bugs mailing
list ( http://www.cygnus.com/ml/egcs-bugs/1998-Jun/0260.html ).

The test case is repeated here:

  template<class M, class T> struct temp2;
  template<template<class> class M, class T> struct temp2<M<T>, T> {};

  template<class M> struct temp1;
  template<template<class> class M, class T> struct temp1<M<T> > {};

The second partial specialization fails with the message

  ta.C:5: template parameters not used in partial specialization:
  ta.C:5:         `T'

because template parameter usage was not properly recorded for 
template template parameters.  In this case, for_each_template_parm 
was not called for the  parameter T inside M<T>.

--Kriang


	* pt.c (for_each_template_parm, case TEMPLATE_DECL): If it is a 
	template template parameter, record its use.
	(for_each_template_parm, case TEMPLATE_TEMPLATE_PARM): Traverse 
	its template arguments if exists.

diff -crNp gcc-old/cp/pt.c gcc/cp/pt.c
*** gcc-old/cp/pt.c	Wed Jun 24 02:19:58 1998
--- gcc/cp/pt.c	Wed Jun 24 02:16:42 1998
*************** for_each_template_parm (t, fn, data)
*** 3257,3266 ****
      case TEMPLATE_DECL:
        /* A template template parameter is encountered */
        if (DECL_TEMPLATE_TEMPLATE_PARM_P (t))
!         /* We are parsing a template declaration */
!         return 1;
!       /* We are instantiating templates with template template
!          parameter */
        return 0;
        
      case CONST_DECL:
--- 3257,3264 ----
      case TEMPLATE_DECL:
        /* A template template parameter is encountered */
        if (DECL_TEMPLATE_TEMPLATE_PARM_P (t))
! 	return for_each_template_parm (TREE_TYPE (t), fn, data);
!       /* Already substituted template template parameter */
        return 0;
        
      case CONST_DECL:
*************** for_each_template_parm (t, fn, data)
*** 3290,3297 ****
        return for_each_template_parm (TREE_OPERAND (t, 0), fn, data);
  
        /* template parm nodes */
-     case TEMPLATE_TYPE_PARM:
      case TEMPLATE_TEMPLATE_PARM:
      case TEMPLATE_PARM_INDEX:
        if (fn)
  	return (*fn)(t, data);
--- 3288,3299 ----
        return for_each_template_parm (TREE_OPERAND (t, 0), fn, data);
  
        /* template parm nodes */
      case TEMPLATE_TEMPLATE_PARM:
+       /* Record template parameters such as `T' inside `TT<T>'.  */
+       if (CLASSTYPE_TEMPLATE_INFO (t)
+ 	  && for_each_template_parm (CLASSTYPE_TI_ARGS (t), fn, data))
+ 	return 1;
+     case TEMPLATE_TYPE_PARM:
      case TEMPLATE_PARM_INDEX:
        if (fn)
  	return (*fn)(t, data);
diff -crNp gcc-old/testsuite/g++.old-deja/g++.pt/ttp45.C gcc/testsuite/g++.old-deja/g++.pt/ttp45.C
*** gcc-old/testsuite/g++.old-deja/g++.pt/ttp45.C	Wed Dec 31 16:00:00 1969
--- gcc/testsuite/g++.old-deja/g++.pt/ttp45.C	Wed Jun 24 02:19:21 1998
***************
*** 0 ****
--- 1,7 ----
+ // Build don't link:
+ 
+ template<class M, class T> struct temp2;
+ template<template<class> class M, class T> struct temp2<M<T>, T> {};
+ 
+ template<class M> struct temp1;
+ template<template<class> class M, class T> struct temp1<M<T> > {};




More information about the Gcc-patches mailing list