C++ PATCH: Pointer-to-member regression fix

Mark Mitchell mark@codesourcery.com
Sun Jul 27 18:26:00 GMT 2003


This patch fixes a regression I introduced into the pointer-to-member
handling during my conversion to the use of OFFSET_TYPE to represent
pointers to data members.

Tested on i686-pc-linux-gnu, applied on the mainline.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2003-07-27  Mark Mitchell  <mark@codesourcery.com>

	* call.c (standard_conversion): Tweak handling of
	pointer-to-member types.
	* pt.c (tsubst): Correctly qualify pointers-to-data member types.
	* typeck.c (comp_ptr_ttypes_real): Check qualifiers on
	pointer-to-data member types.

2003-07-27  Mark Mitchell  <mark@codesourcery.com>

	* g++.dg/template/ptrmem6.C: New test.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.415
diff -c -5 -p -r1.415 call.c
*** cp/call.c	24 Jul 2003 23:33:25 -0000	1.415
--- cp/call.c	27 Jul 2003 18:09:18 -0000
*************** standard_conversion (tree to, tree from,
*** 713,724 ****
  	  to_pointee = TREE_TYPE (to);
  	  from_pointee = TREE_TYPE (from);
  	}
        else
  	{
! 	  to_pointee = to;
! 	  from_pointee = from;
  	}
  
        if (same_type_p (from, to))
  	/* OK */;
        else if (comp_ptr_ttypes (to_pointee, from_pointee))
--- 713,724 ----
  	  to_pointee = TREE_TYPE (to);
  	  from_pointee = TREE_TYPE (from);
  	}
        else
  	{
! 	  to_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (to);
! 	  from_pointee = TYPE_PTRMEM_POINTED_TO_TYPE (from);
  	}
  
        if (same_type_p (from, to))
  	/* OK */;
        else if (comp_ptr_ttypes (to_pointee, from_pointee))
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.738
diff -c -5 -p -r1.738 pt.c
*** cp/pt.c	25 Jul 2003 16:45:34 -0000	1.738
--- cp/pt.c	27 Jul 2003 18:09:19 -0000
*************** tsubst (tree t, tree args, tsubst_flags_
*** 6825,6835 ****
  						   TREE_TYPE (type),
  						   TYPE_ARG_TYPES (type));
  	    return build_ptrmemfunc_type (build_pointer_type (method_type));
  	  }
  	else
! 	  return build_ptrmem_type (r, type);
        }
      case FUNCTION_TYPE:
      case METHOD_TYPE:
        {
  	tree fntype;
--- 6825,6837 ----
  						   TREE_TYPE (type),
  						   TYPE_ARG_TYPES (type));
  	    return build_ptrmemfunc_type (build_pointer_type (method_type));
  	  }
  	else
! 	  return cp_build_qualified_type_real (build_ptrmem_type (r, type),
! 					       TYPE_QUALS (t),
! 					       complain);
        }
      case FUNCTION_TYPE:
      case METHOD_TYPE:
        {
  	tree fntype;
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.486
diff -c -5 -p -r1.486 typeck.c
*** cp/typeck.c	25 Jul 2003 16:52:47 -0000	1.486
--- cp/typeck.c	27 Jul 2003 18:09:22 -0000
*************** comp_ptr_ttypes_real (tree to, tree from
*** 6011,6023 ****
      {
        if (TREE_CODE (to) != TREE_CODE (from))
  	return 0;
  
        if (TREE_CODE (from) == OFFSET_TYPE
! 	  && same_type_p (TYPE_OFFSET_BASETYPE (from),
! 			  TYPE_OFFSET_BASETYPE (to)))
! 	  continue;
  
        /* Const and volatile mean something different for function types,
  	 so the usual checks are not appropriate.  */
        if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
  	{
--- 6011,6023 ----
      {
        if (TREE_CODE (to) != TREE_CODE (from))
  	return 0;
  
        if (TREE_CODE (from) == OFFSET_TYPE
! 	  && !same_type_p (TYPE_OFFSET_BASETYPE (from),
! 			   TYPE_OFFSET_BASETYPE (to)))
! 	return 0;
  
        /* Const and volatile mean something different for function types,
  	 so the usual checks are not appropriate.  */
        if (TREE_CODE (to) != FUNCTION_TYPE && TREE_CODE (to) != METHOD_TYPE)
  	{
*************** comp_ptr_ttypes_real (tree to, tree from
*** 6033,6043 ****
  
  	  if (constp > 0)
  	    constp &= TYPE_READONLY (to);
  	}
  
!       if (TREE_CODE (to) != POINTER_TYPE)
  	return ((constp >= 0 || to_more_cv_qualified)
  		&& same_type_ignoring_top_level_qualifiers_p (to, from));
      }
  }
  
--- 6033,6043 ----
  
  	  if (constp > 0)
  	    constp &= TYPE_READONLY (to);
  	}
  
!       if (TREE_CODE (to) != POINTER_TYPE && !TYPE_PTR_TO_MEMBER_P (to))
  	return ((constp >= 0 || to_more_cv_qualified)
  		&& same_type_ignoring_top_level_qualifiers_p (to, from));
      }
  }
  
Index: testsuite/g++.dg/template/ptrmem6.C
===================================================================
RCS file: testsuite/g++.dg/template/ptrmem6.C
diff -N testsuite/g++.dg/template/ptrmem6.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/ptrmem6.C	27 Jul 2003 18:09:22 -0000
***************
*** 0 ****
--- 1,10 ----
+ struct S {};
+ 
+ void g(int S::**);
+ 
+ template <typename T>
+ void f (int T::* volatile *p) {
+   g(p); // { dg-error "" }
+ }
+ 
+ template void f(int S::* volatile *); // { dg-error "instantiated" }



More information about the Gcc-patches mailing list