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] Fix 21455


Hi,
this patch fixed 21455 an regression due to my cleanup of binfo creation. I reordered the if statement and took advantage of the bk_via_virtual flag to speed things up a tad on mainline. 4.0 contains just the minimal patch.


built and tested on i686-pc-linux-gnu. Installed mainline and 4.0

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2005-05-27  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/21455
	* typeck.c (get_delta_difference): Cope with incomplete but equal
	classes.  Reorder if.

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.629
diff -c -3 -p -r1.629 typeck.c
*** cp/typeck.c	24 May 2005 22:22:33 -0000	1.629
--- cp/typeck.c	27 May 2005 15:22:26 -0000
*************** get_delta_difference (tree from, tree to
*** 5523,5529 ****
  		      bool c_cast_p)
  {
    tree binfo;
-   tree virt_binfo;
    base_kind kind;
    tree result;
  
--- 5523,5528 ----
*************** get_delta_difference (tree from, tree to
*** 5532,5567 ****
    binfo = lookup_base (to, from, c_cast_p ? ba_unique : ba_check, &kind);
    if (kind == bk_inaccessible || kind == bk_ambig)
      error ("   in pointer to member function conversion");
!   else if (!binfo)
      {
!       if (!allow_inverse_p)
! 	{
! 	  error_not_base_type (from, to);
! 	  error ("   in pointer to member conversion");
! 	}
!       else
! 	{
! 	  binfo = lookup_base (from, to, c_cast_p ? ba_unique : ba_check, 
! 			       &kind);
! 	  if (binfo)
! 	    {
! 	      virt_binfo = binfo_from_vbase (binfo);
! 	      if (virt_binfo)
! 		/* This is a reinterpret cast, we choose to do nothing.  */
! 		warning (0, "pointer to member cast via virtual base %qT",
! 			 BINFO_TYPE (virt_binfo));
! 	      else
! 		result = size_diffop (size_zero_node, BINFO_OFFSET (binfo));
! 	    }
! 	}
!     }
!   else
!     {
!       virt_binfo = binfo_from_vbase (binfo);
!       if (!virt_binfo)
  	result = BINFO_OFFSET (binfo);
        else
  	{
  	  /* This is a reinterpret cast, we choose to do nothing.  */
  	  if (allow_inverse_p)
  	    warning (0, "pointer to member cast via virtual base %qT",
--- 5531,5544 ----
    binfo = lookup_base (to, from, c_cast_p ? ba_unique : ba_check, &kind);
    if (kind == bk_inaccessible || kind == bk_ambig)
      error ("   in pointer to member function conversion");
!   else if (binfo)
      {
!       if (kind != bk_via_virtual)
  	result = BINFO_OFFSET (binfo);
        else
  	{
+ 	  tree virt_binfo = binfo_from_vbase (binfo);
+ 	  
  	  /* This is a reinterpret cast, we choose to do nothing.  */
  	  if (allow_inverse_p)
  	    warning (0, "pointer to member cast via virtual base %qT",
*************** get_delta_difference (tree from, tree to
*** 5571,5576 ****
--- 5548,5577 ----
  		   BINFO_TYPE (virt_binfo));
  	}
      }
+   else if (same_type_ignoring_top_level_qualifiers_p (from, to))
+     /* Pointer to member of incomplete class is permitted*/;
+   else if (!allow_inverse_p)
+     {
+       error_not_base_type (from, to);
+       error ("   in pointer to member conversion");
+     }
+   else
+     {
+       binfo = lookup_base (from, to, c_cast_p ? ba_unique : ba_check, &kind);
+       if (binfo)
+ 	{
+ 	  if (kind != bk_via_virtual)
+ 	    result = size_diffop (size_zero_node, BINFO_OFFSET (binfo));
+ 	  else
+ 	    {
+ 	      /* This is a reinterpret cast, we choose to do nothing.  */
+ 	      tree virt_binfo = binfo_from_vbase (binfo);
+ 	  
+ 	      warning (0, "pointer to member cast via virtual base %qT",
+ 		       BINFO_TYPE (virt_binfo));
+ 	    }
+ 	}
+     }
  
    return fold_if_not_in_template (convert_to_integer (ptrdiff_type_node, 
  						      result));
2005-05-27  Nathan Sidwell  <nathan@codesourcery.com>

	PR c++/21455
	* typeck.c (get_delta_difference): Cope with incomplete but equal
	classes.

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.616.2.6
diff -c -3 -p -r1.616.2.6 typeck.c
*** cp/typeck.c	17 Apr 2005 03:37:34 -0000	1.616.2.6
--- cp/typeck.c	27 May 2005 15:50:04 -0000
*************** get_delta_difference (tree from, tree to
*** 5535,5541 ****
      error ("   in pointer to member function conversion");
    else if (!binfo)
      {
!       if (!allow_inverse_p)
  	{
  	  error_not_base_type (from, to);
  	  error ("   in pointer to member conversion");
--- 5535,5543 ----
      error ("   in pointer to member function conversion");
    else if (!binfo)
      {
!       if (!binfo && same_type_ignoring_top_level_qualifiers_p (from, to))
! 	/* Pointer to member of incomplete class is permitted*/;
!       else if (!allow_inverse_p)
  	{
  	  error_not_base_type (from, to);
  	  error ("   in pointer to member conversion");
// Copyright (C) 2005 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 26 May 2005 <nathan@codesourcery.com>

// Origin:Volker Reichelt reichelt@gcc.gnu.org
// PR 21681. ICE with inappropriate access check.

template<int X> struct A;

struct B
{
    template<int N> void foo()
    {
        A<N>::X::Y;
    }
};

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