C++ PATCH for pointer-to-member functions

Mark Mitchell mark@codesourcery.com
Wed Mar 31 18:59:00 GMT 1999


This patch fixes a minor problem with the new pointer-to-member
function handling.

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

1999-03-23  Mark Mitchell  <mark@codesourcery.com>

	* pt.c (convert_nontype_argument): Don't create things that aren't
	PTRMEM_CSTs when applying a qualification conversion to a
	PTRMEM_CST.

Index: testsuite/g++.old-deja/g++.pt/ptrmem7.C
===================================================================
RCS file: ptrmem7.C
diff -N ptrmem7.C
*** /dev/null	Sat Dec  5 20:30:03 1998
--- ptrmem7.C	Tue Mar 23 15:07:37 1999
***************
*** 0 ****
--- 1,21 ----
+ // Build don't link:
+ // Origin: Jason Merrill <jason@cygnus.com>
+ 
+ struct A
+ {
+   A() : x(123) { }
+   int x;
+ };
+ A a;
+ 
+ template<const int A::*PX>
+ struct B
+ {
+   static int g() { return a.*PX; }
+ };
+ 
+ 
+ int main(int argc, char *argv[])
+ {
+   int n = B<&A::x>::g();
+ }
Index: cp/pt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/pt.c,v
retrieving revision 1.271
diff -c -p -r1.271 pt.c
*** pt.c	1999/03/23 00:01:46	1.271
--- pt.c	1999/03/23 23:07:44
*************** convert_nontype_argument (type, expr)
*** 2703,2712 ****
  	tree type_pointed_to = TREE_TYPE (type);
   
  	if (TYPE_PTRMEM_P (type))
! 	  /* For a non-type template-parameter of type pointer to data
! 	     member, qualification conversions (_conv.qual_) are
! 	     applied.  */
! 	  return perform_qualification_conversions (type, expr);
  	else if (TREE_CODE (type_pointed_to) == FUNCTION_TYPE)
  	  { 
  	    /* For a non-type template-parameter of type pointer to
--- 2703,2730 ----
  	tree type_pointed_to = TREE_TYPE (type);
   
  	if (TYPE_PTRMEM_P (type))
! 	  {
! 	    tree e;
! 
! 	    /* For a non-type template-parameter of type pointer to data
! 	       member, qualification conversions (_conv.qual_) are
! 	       applied.  */
! 	    e = perform_qualification_conversions (type, expr);
! 	    if (TREE_CODE (e) == NOP_EXPR)
! 	      {
! 		/* The call to perform_qualification_conversions will
! 		   insert a NOP_EXPR over EXPR to do express
! 		   conversion, if necessary.  But, that will confuse
! 		   us if we use this (converted) template parameter to
! 		   instantiate another template; then the thing will
! 		   not look like a valid template argument.  So, just
! 		   make a new constant, of the appropriate type.  */
! 		e = make_node (PTRMEM_CST);
! 		TREE_TYPE (e) = type;
! 		PTRMEM_CST_MEMBER (e) = PTRMEM_CST_MEMBER (expr);
! 	      }
! 	    return e;
! 	  }
  	else if (TREE_CODE (type_pointed_to) == FUNCTION_TYPE)
  	  { 
  	    /* For a non-type template-parameter of type pointer to



More information about the Gcc-patches mailing list