Patch for too-lenient handling of pointer-to-member conversions

Mike Stump mrs@wrs.com
Wed Feb 11 17:22:00 GMT 1998


> Date: Wed, 11 Feb 1998 15:57:51 -0800
> From: Mark Mitchell <mmitchell@usa.net>
> To: Jason Merrill <jason@cygnus.com>
> Cc: egcs-bugs@cygnus.com, Corey Kosak <kosak@cs.cmu.edu>

>   Here's a patch to make sure that we don't allow code like this:

>     struct S { void f(int); }
>     void (S::*sp)(char*) = &S::f;

>   Is it OK to check this in?

> +       pfn_type = TYPE_PTRMEMFUNC_FN_TYPE (TREE_TYPE (pfn));
> +       if (!force
> + 	  && (/* Check the class types.  Recall that a
> + 		 pointer-to-member-of-base can be converted to a
> + 		 pointer-to-member-of-derived but not vice versa.  */
> + 	      !ACCESSIBLY_UNIQUELY_DERIVED_P (TYPE_METHOD_BASETYPE
> + 					      (TREE_TYPE (pfn_type)),
> + 					      TYPE_METHOD_BASETYPE 
> + 					      (TREE_TYPE (type)))

I'm thinking this should be in get_delta_difference.  There are many
calls to get_delta_difference and I think they all need to check, if
it checks, then the callers don't have to.

> + 	      /* Check the argument types, except `this'.  */
> + 	      || !compparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (type))), 
> + 			     TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (pfn_type))),

This part looks fine, though I think the other call to
get_delta_difference below might need it as well.

> + 			     1)
> + 	      /* Check the return types.  */
> + 	      || !comptypes (TREE_TYPE (TREE_TYPE (type)),
> + 			     TREE_TYPE (TREE_TYPE (pfn_type)), 1)))

There are some conversions allowed on the return type (covariant
returns), and I think we should allow them.



More information about the Gcc-bugs mailing list