PATCH for Re: Problem with template, which has a pointer-to-member parameter, when instantiated more than once in a given source file

Mark Mitchell mark@markmitchell.com
Sun May 24 22:06:00 GMT 1998


>>>>> "Loren" == Loren J Rittle <rittle@supra.rsch.comm.mot.com> writes:

Here's a patch for your problem.  Jason, OK?

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com

1998-05-24  Mark Mitchell  <mark@markmitchell.com>

	* tree.c (cp_tree_equal): Handle pointers to member functions.

Index: nontype4.C
===================================================================
RCS file: nontype4.C
diff -N nontype4.C
*** /dev/null	Mon Dec 31 20:00:00 1979
--- nontype4.C	Sun May 24 21:26:55 1998
***************
*** 0 ****
--- 1,31 ----
+ // Build don't link:
+ 
+ template <class R, void (R::* A) (void)>
+ class s
+ {
+ public:
+   s (R &r) : _r (r) {}
+ 
+   void e (void) { (_r.*A) (); }
+ 
+ private:
+   R &_r;
+ };
+ 
+ class x
+ {
+ public:
+   void test1 (void) { int j = 0; }
+   void test2 (void) { int j = 1; }
+ };
+ 
+ int
+ main (void)
+ {
+   x r;
+ 
+   s<x, &x::test1> c4 (r);
+   s<x, &x::test2> c5 (r);
+ 
+   return 0;
+ }
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.42
diff -c -p -r1.42 tree.c
*** tree.c	1998/05/23 02:18:33	1.42
--- tree.c	1998/05/25 04:27:27
*************** cp_tree_equal (t1, t2)
*** 2134,2140 ****
  		  TREE_STRING_LENGTH (t1));
  
      case CONSTRUCTOR:
!       abort ();
  
      case SAVE_EXPR:
        return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
--- 2134,2156 ----
  		  TREE_STRING_LENGTH (t1));
  
      case CONSTRUCTOR:
!       /* We need to do this when determining whether or not two
! 	 non-type pointer to member function template arguments
! 	 are the same.  */
!       if (!(comptypes (TREE_TYPE (t1), TREE_TYPE (t2), 1)
! 	    /* The first operand is RTL.  */
! 	    && TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
! 	return 0;
!       return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
! 
!     case TREE_LIST:
!       cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
!       if (cmp <= 0)
! 	return cmp;
!       cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2));
!       if (cmp <= 0)
! 	return cmp;
!       return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
  
      case SAVE_EXPR:
        return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));



More information about the Gcc-bugs mailing list