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]

Re: [C++ PATCH] Fix bug 827


Jason Merrill wrote:
> 
> >>>>> "Nathan" == Nathan Sidwell <nathan@codesourcery.com> writes:
> > built & tested on i686-pc-linux-gnu. ok?
> Yes, thanks.
done.

> > [It doesn't revert the above adjustment behaviour -- I'll get to that]
This patch does remove that adjustment, however it breaks g++.mike/pmf5.C
(attached), which expects it to work. Does that mean there's code out there
which expects this behaviour? Thoughts?

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
2000-12-01  Nathan Sidwell  <nathan@codesourcery.com>

	* typeck.c (get_delta_difference): If via a virtual base, return
	zero.
	* cvt.c (cp_convert_to_pointer): Likewise.

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.323
diff -c -3 -p -r1.323 typeck.c
*** typeck.c	2000/12/01 11:52:32	1.323
--- typeck.c	2000/12/01 12:53:51
*************** get_delta_difference (from, to, force)
*** 5936,5966 ****
        virt_binfo = binfo_from_vbase (binfo);
        
        if (virt_binfo)
!         cp_warning ("pointer to member cast via virtual base `%T' of `%T' will only work for objects of dynamic type `%T'",
! 	            BINFO_TYPE (virt_binfo),
! 	            BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)), from);
        delta = BINFO_OFFSET (binfo);
        delta = cp_convert (ptrdiff_type_node, delta);
!       
!       return cp_build_binary_op (MINUS_EXPR,
  				 integer_zero_node,
  				 delta);
      }
  
    virt_binfo = binfo_from_vbase (binfo);
    if (virt_binfo)
      {
        if (force)
!         cp_warning ("pointer to member cast via virtual base `%T' of `%T' will only work for objects of dynamic type `%T'",
                      BINFO_TYPE (virt_binfo),
!                     BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)), to);
        else
  	cp_error ("pointer to member conversion via virtual base `%T' of `%T'",
  		  BINFO_TYPE (virt_binfo),
                    BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
      }
  
!   return BINFO_OFFSET (binfo);
  }
  
  /* Return a constructor for the pointer-to-member-function TYPE using
--- 5936,5974 ----
        virt_binfo = binfo_from_vbase (binfo);
        
        if (virt_binfo)
!         {
!           /* This is a reinterpret cast, we choose to do nothing. */
!           cp_warning ("pointer to member cast via virtual base `%T' of `%T'",
! 	              BINFO_TYPE (virt_binfo),
! 	              BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
!           return delta;
!         }
        delta = BINFO_OFFSET (binfo);
        delta = cp_convert (ptrdiff_type_node, delta);
!       delta = cp_build_binary_op (MINUS_EXPR,
  				 integer_zero_node,
  				 delta);
+ 
+       return delta;
      }
  
    virt_binfo = binfo_from_vbase (binfo);
    if (virt_binfo)
      {
+       /* This is a reinterpret cast, we choose to do nothing. */
        if (force)
!         cp_warning ("pointer to member cast via virtual base `%T' of `%T'",
                      BINFO_TYPE (virt_binfo),
!                     BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
        else
  	cp_error ("pointer to member conversion via virtual base `%T' of `%T'",
  		  BINFO_TYPE (virt_binfo),
                    BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
+       return delta;
      }
+   delta = BINFO_OFFSET (binfo);
  
!   return cp_convert (ptrdiff_type_node, delta);
  }
  
  /* Return a constructor for the pointer-to-member-function TYPE using
Index: cp/cvt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cvt.c,v
retrieving revision 1.90
diff -c -3 -p -r1.90 cvt.c
*** cvt.c	2000/11/27 10:55:30	1.90
--- cvt.c	2000/12/01 12:53:52
*************** cp_convert_to_pointer (type, expr, force
*** 209,218 ****
            if (virt_binfo)
  	    {
  	      if (force)
! 	        cp_warning ("pointer to member cast via virtual base `%T' of `%T' will only work for objects of dynamic type `%T'",
  	                    BINFO_TYPE (virt_binfo),
!                             BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)),
!                             code == MINUS_EXPR ? b2 : b1);
                else
                  {
  	          cp_error ("pointer to member cast via virtual base `%T' of `%T'",
--- 209,217 ----
            if (virt_binfo)
  	    {
  	      if (force)
! 	        cp_warning ("pointer to member cast via virtual base `%T' of `%T'",
  	                    BINFO_TYPE (virt_binfo),
!                             BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
                else
                  {
  	          cp_error ("pointer to member cast via virtual base `%T' of `%T'",
*************** cp_convert_to_pointer (type, expr, force
*** 220,232 ****
                              BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
  	          return error_mark_node;
  	        }
  	    }
  	      
  	  if (TREE_CODE (expr) == PTRMEM_CST)
  	    expr = cplus_expand_constant (expr);
  
! 	  if (binfo && ! TREE_VIA_VIRTUAL (binfo))
! 	    expr = size_binop (code, convert (sizetype,expr),
  			       BINFO_OFFSET (binfo));
  	}
        else if (TYPE_PTRMEMFUNC_P (type))
--- 219,234 ----
                              BINFO_TYPE (BINFO_INHERITANCE_CHAIN (virt_binfo)));
  	          return error_mark_node;
  	        }
+ 	      /* This is a reinterpret cast, whose result is unspecified.
+ 	         We choose to do nothing.  */
+ 	      return expr;
  	    }
  	      
  	  if (TREE_CODE (expr) == PTRMEM_CST)
  	    expr = cplus_expand_constant (expr);
  
! 	  if (binfo)
! 	    expr = size_binop (code, convert (sizetype, expr),
  			       BINFO_OFFSET (binfo));
  	}
        else if (TYPE_PTRMEMFUNC_P (type))
// Special g++ Options: -w

class A {
  int j;
};

class Space {
  int j;
};

typedef int (A::*pma)();

class B : public Space, virtual public A {
public:
  int i;
  int foo () {
    return i!=42;
  }
  B() {
    i = 42;
  }
};

int call_base (A* ap, pma pmf) {
  return (ap->*pmf)();
}

int main() {
  B b;
  return call_base ((A*)&b, (pma)&B::foo);
}

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