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: patch:jet another bug in dynamic_cast


Alfred Minarik wrote:
> 
> But your patches fail my testcases.
> I will try to merge both batches
> (doing also my error in reading the statndard right)
> stay tuned...
> 
(ignore those silly spelling mistakes and all those
that will follow ...)

Well I have merged them together in a sense.
This is I have decided to leave dcast as
it stands (or as it stands after Swindells patch)
and do all my corrections in __dynamic_cast()
within tinfo2.cc.
So both patches are independent and fix different
problems.

Also my patch has in fact become quite short
and clear.

After applying Swindells and my patches
both Swindells and my testcases succeed.

Applying only my patch will address
all the errors reported in my first
mail, but not the vitual base class problem.

Alfred
*** egcs-19990608.orig/gcc/cp/tinfo2.cc	Wed Dec 16 22:16:15 1998
--- egcs-19990608/gcc/cp/tinfo2.cc	Tue Jun 15 10:37:20 1999
***************
*** 278,285 ****
  		int require_public, void *address,
  		const type_info & (*sub)(void), void *subptr)
  {
!   return static_cast <const __user_type_info &> (from ()).dcast
!     (to (), require_public, address, &(sub ()), subptr);
  }
  
  // type_info nodes and functions for the builtin types.  The mangling here
--- 278,316 ----
  		int require_public, void *address,
  		const type_info & (*sub)(void), void *subptr)
  {
!   const __user_type_info& 
!     _from = static_cast <const __user_type_info &> (from ());	
!   const __user_type_info& 
!     _to = static_cast <const __user_type_info &> (to ());
!   const __user_type_info& 
!     _sub = static_cast <const __user_type_info &> (sub ());
!   	
!   //as dcast does not correctly handle valid downcasts within
!   //private bases and nonpublic inheritance within
!   //a found downcast - work around it this way:
!   //first let dcast find any down or crosscast pretending
!   //all bases are public: This will do correct ambiguous check
!   //for us. if no cast can be found here, non could be
!   //found later.
!   void* tmp = _from.dcast(_to, 0, address, &_sub, subptr);
!   if(tmp == 0) 
!     return 0;
!   else
!     {
!       //Check if it was a valid downcast respecting
!       //nonpublic inheritance
!       void* tmp2 = _to.dcast(_sub, require_public, tmp, &_sub, subptr);
!       if(tmp2) 
!         return tmp;
!       //So why did the first call succeed
!       //Check if it was a downcast through nonpublic inheritance
!       tmp2 = _to.dcast(_sub, 0, tmp, &_sub, subptr);
!       if(tmp2) 
!         return 0;
!       //So it must had been a crosscast.
!       //check if there is an unambiguous and public reachable _to.	
!       return _from.dcast(_to, require_public, address);
!     }
  }
  
  // type_info nodes and functions for the builtin types.  The mangling here



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