PATCH for pointers-to-members + STL

Mark Mitchell mark@codesourcery.com
Fri Aug 6 11:26:00 GMT 1999


I don't recall who reported this problem.  We were not doing the right
thing with cv-qualified pointers-to-members; it is not just the
RECORD_TYPE that must be cv-qualified, but also the type of the
function pointer that it contains.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-08-06  Mark Mitchell  <mark@codesourcery.com>

	* tree.c (cp_build_qualified_type_real): Handle
	pointer-to-member-function types correctly.

Index: testsuite/g++.old-deja/g++.pt/ptrmem8.C
===================================================================
RCS file: ptrmem8.C
diff -N ptrmem8.C
*** /dev/null	Sat Dec  5 20:30:03 1998
--- ptrmem8.C	Fri Aug  6 11:18:12 1999
***************
*** 0 ****
--- 1,18 ----
+ // Build don't link:
+ // Origin: Mark Mitchell <mark@codesourcery.com>
+ 
+ template <class T>
+ struct S 
+ {
+   void f (const T&);
+   void f (T&);
+ };
+ 
+ class C 
+ {
+ };
+ 
+ typedef int (C::*cp)();
+ 
+ template struct S<cp>;
+ 
Index: tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/tree.c,v
retrieving revision 1.122
diff -c -p -r1.122 tree.c
*** tree.c	1999/08/04 09:07:49	1.122
--- tree.c	1999/08/06 18:24:32
*************** cp_build_qualified_type_real (type, type
*** 503,508 ****
--- 503,510 ----
       int type_quals;
       int complain;
  {
+   tree result;
+ 
    if (type == error_mark_node)
      return type;
    
*************** cp_build_qualified_type_real (type, type
*** 570,577 ****
        TYPE_NEEDS_DESTRUCTOR (t) 
  	= TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
        return t;
      }
!   return build_qualified_type (type, type_quals);
  }
  
  /* Returns the canonical version of TYPE.  In other words, if TYPE is
--- 572,604 ----
        TYPE_NEEDS_DESTRUCTOR (t) 
  	= TYPE_NEEDS_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type));
        return t;
+     }
+   else if (TYPE_PTRMEMFUNC_P (type))
+     {
+       /* For a pointer-to-member type, we can't just return a
+ 	 cv-qualified version of the RECORD_TYPE.  If we do, we
+ 	 haven't change the field that contains the actual pointer to
+ 	 a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong.  */
+       tree t;
+ 
+       t = TYPE_PTRMEMFUNC_FN_TYPE (type);
+       t = cp_build_qualified_type_real (t, type_quals, complain);
+       return build_qualified_type (build_ptrmemfunc_type (t), type_quals);
      }
! 
!   /* Retrieve (or create) the appropriately qualified variant.  */
!   result = build_qualified_type (type, type_quals);
! 
!   /* If this was a pointer-to-method type, and we just made a copy,
!      then we need to clear the cached associated
!      pointer-to-member-function type; it is not valid for the new
!      type.  */
!   if (result != type 
!       && TREE_CODE (type) == POINTER_TYPE
!       && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE)
!     TYPE_SET_PTRMEMFUNC_TYPE (result, NULL_TREE);
! 
!   return result;
  }
  
  /* Returns the canonical version of TYPE.  In other words, if TYPE is


More information about the Gcc-patches mailing list