This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Revert static_cast patch


Hi,
Jason has pointed out that 
> 2000-12-01  Nathan Sidwell  <nathan@codesourcery.com>
> 
>         * call.c (standard_conversion): Reject pointer to member
>         conversions from ambiguous, inaccessible or virtual bases.
>         * typeck.c (build_static_cast): Don't check pointers to members
>         specially.
> 
> is wrong; the standard says
> 
> 2 An  rvalue of type "pointer to member of B of type cv T," where B is a
>   class type, can be converted to an rvalue of type "pointer  to  member
>   of   D   of   type   cv T,"   where  D  is  a  derived  class  (clause
>   _class.derived_)  of   B.    If   B   is   an   inaccessible   (clause
>   _class.access_),    ambiguous   (_class.member.lookup_)   or   virtual
>   (_class.mi_) base class of D, a program that necessitates this conver-
>   sion  is  ill-formed.
> 
> Your change causes us to decide that there is no conversion in those cases;
> there is, it's just ill-formed.  This distinction affects overload
> resolution, i.e. for
This patch reverts that, and fixes the problem with adding qualifiers
to pointer to members.

built & tested on i686-pc-linux-gnu, ok for 3.1 & mainline?

nathan

-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2002-03-04  Nathan Sidwell  <nathan@codesourcery.com>

	Revert 2000-12-01  Nathan Sidwell  <nathan@codesourcery.com>,
	It is incorrect.
	* typeck.c (build_static_cast): Compare non-qualified types
	with pointer to member conversions.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/call.c,v
retrieving revision 1.307
diff -c -3 -p -r1.307 call.c
*** call.c	2002/02/07 20:51:11	1.307
--- call.c	2002/03/04 08:30:06
*************** standard_conversion (to, from, expr)
*** 795,803 ****
  	{
  	  tree fbase = TYPE_OFFSET_BASETYPE (TREE_TYPE (from));
  	  tree tbase = TYPE_OFFSET_BASETYPE (TREE_TYPE (to));
- 	  tree binfo = lookup_base (tbase, fbase, ba_check, NULL);
  
! 	  if (binfo && !binfo_from_vbase (binfo)
  	      && (same_type_ignoring_top_level_qualifiers_p
  		  (TREE_TYPE (TREE_TYPE (from)),
  		   TREE_TYPE (TREE_TYPE (to)))))
--- 795,802 ----
  	{
  	  tree fbase = TYPE_OFFSET_BASETYPE (TREE_TYPE (from));
  	  tree tbase = TYPE_OFFSET_BASETYPE (TREE_TYPE (to));
  
! 	  if (DERIVED_FROM_P (fbase, tbase)
  	      && (same_type_ignoring_top_level_qualifiers_p
  		  (TREE_TYPE (TREE_TYPE (from)),
  		   TREE_TYPE (TREE_TYPE (to)))))
*************** standard_conversion (to, from, expr)
*** 843,851 ****
        tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
        tree fbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn)));
        tree tbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn)));
-       tree binfo = lookup_base (tbase, fbase, ba_check, NULL);
  
!       if (!binfo || binfo_from_vbase (binfo)
  	  || !same_type_p (TREE_TYPE (fromfn), TREE_TYPE (tofn))
  	  || !compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn)),
  			 TREE_CHAIN (TYPE_ARG_TYPES (tofn)))
--- 842,849 ----
        tree tofn = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (to));
        tree fbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (fromfn)));
        tree tbase = TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (tofn)));
  
!       if (!DERIVED_FROM_P (fbase, tbase)
  	  || !same_type_p (TREE_TYPE (fromfn), TREE_TYPE (tofn))
  	  || !compparms (TREE_CHAIN (TYPE_ARG_TYPES (fromfn)),
  			 TREE_CHAIN (TYPE_ARG_TYPES (tofn)))
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.389
diff -c -3 -p -r1.389 typeck.c
*** typeck.c	2002/03/01 13:50:26	1.389
--- typeck.c	2002/03/04 08:31:46
*************** build_static_cast (type, expr)
*** 5078,5083 ****
--- 5078,5099 ----
  	  && kind != bk_via_virtual)
  	ok = 1;
      }
+   else if (TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))
+     {
+       /* They're pointers to members. The pointed to objects must be
+ 	 the same (ignoring CV qualifiers), and the containing classes
+ 	 must be related non-virtually. */
+       base_kind kind;
+       
+       if (same_type_p
+ 	  (strip_all_pointer_quals (TREE_TYPE (TREE_TYPE (type))),
+ 	   strip_all_pointer_quals (TREE_TYPE (TREE_TYPE (intype))))
+  	  && (lookup_base (TYPE_OFFSET_BASETYPE (TREE_TYPE (intype)),
+ 			   TYPE_OFFSET_BASETYPE (TREE_TYPE (type)),
+ 			   ba_ignore | ba_quiet, &kind))
+  	  && kind != bk_via_virtual)
+   	ok = 1;
+     }
    else if (TREE_CODE (intype) != BOOLEAN_TYPE
  	   && TREE_CODE (type) != ARRAY_TYPE
  	   && TREE_CODE (type) != FUNCTION_TYPE
// { dg-do compile }

// Copyright (C) 2002 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 04 Mar 2002 <nathan@codesourcery.com>
//		  Jason Merrill <jason@redhat.com>

struct A { int i; };
struct B: private A {};
struct C {
  C (int A::*);
};

int A::*aip = &A::i;

void f (int B::*) {}  // should choose this, even though it's ill-formed
void f (C) {}         // even though this would be well-formed

int main ()
{
  f (aip);  // { dg-error "`A' is an inaccessible base of `B'" "" }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]