This is the mail archive of the gcc-bugs@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]

PATCH for problem with non-type arguments in templates



Here's a patch for some tricky cases making use of constant
declarations as template arguments.  Jason?

-- 
Mark Mitchell <mmitchell@usa.net>
http://home.earthlink.net/~mbmitchell
Consulting Services Available

Tue Mar 24 11:03:01 1998  Mark Mitchell  <mmitchell@usa.net>

	* tree.c (mapcar): When dealing with a DECL, use it's constant
	value, if any.
	* pt.c (lookup_template_class): Don't mangle the names of template
	classes whose arguments are unknown.
	
Index: cp/tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.25
diff -c -p -r1.25 tree.c
*** tree.c	1998/03/12 00:29:16	1.25
--- tree.c	1998/03/24 18:54:09
*************** mapcar (t, func)
*** 1473,1480 ****
        /* Rather than aborting, return error_mark_node.  This allows us
  	 to report a sensible error message on code like this:
  
! 	 void g() { int i; f<i>(7); } */
!       return error_mark_node;
  
      case PARM_DECL:
        {
--- 1473,1490 ----
        /* Rather than aborting, return error_mark_node.  This allows us
  	 to report a sensible error message on code like this:
  
! 	 void g() { int i; f<i>(7); } 
! 
!          In a case like:
! 
!            void g() { const int i = 7; f<i>(7); }
! 
! 	 however, we must actually return the constant initializer.  */
!       tmp = decl_constant_value (t);
!       if (tmp != t)
! 	return mapcar (tmp, func);
!       else
! 	return error_mark_node;
  
      case PARM_DECL:
        {
Index: cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.104
diff -c -p -r1.104 pt.c
*** pt.c	1998/03/24 10:25:40	1.104
--- pt.c	1998/03/24 18:54:26
*************** lookup_template_class (d1, arglist, in_d
*** 2827,2833 ****
  
        /* We need to set this again after CLASSTYPE_TEMPLATE_INFO is set up.  */
        DECL_ASSEMBLER_NAME (TYPE_MAIN_DECL (t)) = id;
!       /* if (! uses_template_parms (arglist)) */
  	DECL_ASSEMBLER_NAME (TYPE_MAIN_DECL (t)) 
  	  = get_identifier (build_overload_name (t, 1, 1));
  
--- 2827,2833 ----
  
        /* We need to set this again after CLASSTYPE_TEMPLATE_INFO is set up.  */
        DECL_ASSEMBLER_NAME (TYPE_MAIN_DECL (t)) = id;
!       if (! uses_template_parms (arglist))
  	DECL_ASSEMBLER_NAME (TYPE_MAIN_DECL (t)) 
  	  = get_identifier (build_overload_name (t, 1, 1));
  
Index: testsuite/g++.old-deja/g++.pt/explicit68.C
===================================================================
RCS file: explicit68.C
diff -N explicit68.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- explicit68.C	Tue Mar 24 10:54:26 1998
***************
*** 0 ****
--- 1,22 ----
+ template <bool B>
+ struct S
+ {
+   static void g();
+ };
+ 
+ template <bool B>
+ void g();
+ 
+ template<unsigned Length>
+ void f()
+ {
+   const bool b = true;
+   g<b>();
+   const bool b1 = (Length == 2);
+   S<b1>::g();
+ }
+ 
+ void h()
+ {
+   f<3>();
+ }


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