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: PR 14803


This patch fixes PR c++/14803, a case where we were generating invalid
trees, which lead to spurious warnings.

This patch was applied on the mainline; a simpler version which simply
inserts a call to "fold" on every return statement was applied on the
3.4 branch.  Tested on i686-pc-linux-gnu.

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

2004-04-01  Mark Mitchell  <mark@codesourcery.com>

	PR c++/14803
	* typeck.c (get_delta_difference): Call fold before returning the
	value.

2004-04-01  Mark Mitchell  <mark@codesourcery.com>

	PR c++/14803
	* g++.dg/inherit/ptrmem1.C: New test.

Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.519.2.13
diff -c -5 -p -r1.519.2.13 typeck.c
*** cp/typeck.c	20 Mar 2004 00:13:18 -0000	1.519.2.13
--- cp/typeck.c	1 Apr 2004 23:06:53 -0000
*************** static tree
*** 5317,5371 ****
  get_delta_difference (tree from, tree to, int force)
  {
    tree binfo;
    tree virt_binfo;
    base_kind kind;
!   
    binfo = lookup_base (to, from, ba_check, &kind);
    if (kind == bk_inaccessible || kind == bk_ambig)
!     {
!       error ("   in pointer to member function conversion");
!       goto error;
!     }
!   if (!binfo)
      {
        if (!force)
  	{
  	  error_not_base_type (from, to);
  	  error ("   in pointer to member conversion");
- 	  goto error;
  	}
!       binfo = lookup_base (from, to, ba_check, &kind);
!       if (!binfo)
! 	goto error;
        virt_binfo = binfo_from_vbase (binfo);
!       if (virt_binfo)
!         {
!           /* This is a reinterpret cast, we choose to do nothing.  */
!           warning ("pointer to member cast via virtual base `%T'",
  		   BINFO_TYPE (virt_binfo));
! 	  goto error;
!         }
!       return convert_to_integer (ptrdiff_type_node, 
! 				 size_diffop (size_zero_node,
! 					      BINFO_OFFSET (binfo)));
      }
  
!   virt_binfo = binfo_from_vbase (binfo);
!   if (!virt_binfo)
!     return convert_to_integer (ptrdiff_type_node, BINFO_OFFSET (binfo));
! 
!   /* This is a reinterpret cast, we choose to do nothing.  */
!   if (force)
!     warning ("pointer to member cast via virtual base `%T'",
! 	     BINFO_TYPE (virt_binfo));
!   else
!     error ("pointer to member conversion via virtual base `%T'",
! 	   BINFO_TYPE (virt_binfo));
! 
!  error:
!   return convert_to_integer(ptrdiff_type_node, integer_zero_node);
  }
  
  /* Return a constructor for the pointer-to-member-function TYPE using
     the other components as specified.  */
  
--- 5317,5373 ----
  get_delta_difference (tree from, tree to, int force)
  {
    tree binfo;
    tree virt_binfo;
    base_kind kind;
!   tree result;
! 
!   /* Assume no conversion is required.  */
!   result = integer_zero_node;
    binfo = lookup_base (to, from, ba_check, &kind);
    if (kind == bk_inaccessible || kind == bk_ambig)
!     error ("   in pointer to member function conversion");
!   else if (!binfo)
      {
        if (!force)
  	{
  	  error_not_base_type (from, to);
  	  error ("   in pointer to member conversion");
  	}
!       else
! 	{
! 	  binfo = lookup_base (from, to, 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 ("pointer to member cast via virtual base `%T'",
! 			 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 (force)
! 	    warning ("pointer to member cast via virtual base `%T'",
! 		     BINFO_TYPE (virt_binfo));
! 	  else
! 	    error ("pointer to member conversion via virtual base `%T'",
  		   BINFO_TYPE (virt_binfo));
! 	}
      }
  
!   return fold (convert_to_integer (ptrdiff_type_node, result));
  }
  
  /* Return a constructor for the pointer-to-member-function TYPE using
     the other components as specified.  */
  
Index: testsuite/g++.dg/inherit/ptrmem1.C
===================================================================
RCS file: testsuite/g++.dg/inherit/ptrmem1.C
diff -N testsuite/g++.dg/inherit/ptrmem1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/inherit/ptrmem1.C	1 Apr 2004 23:11:55 -0000
***************
*** 0 ****
--- 1,21 ----
+ // PR c++/14803
+ // { dg-options "-Werror" }
+ 
+ struct sc_module { int member; };
+ 
+ struct sc_signal_in_if { bool state; };
+ 
+ typedef void (sc_module::*SC_ENTRY_FUNC)();
+ 
+ class sc_clock : public sc_signal_in_if, public sc_module
+ {
+ public:
+   sc_clock();
+   void posedge_action();
+   SC_ENTRY_FUNC fptr;
+ };
+ 
+ sc_clock::sc_clock()
+ {
+   fptr = static_cast<SC_ENTRY_FUNC>(&sc_clock::posedge_action);
+ }


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