[Issue 1563] dynamic cast is not always performed

BCS ao at pathlink.com
Tue Oct 9 21:10:51 PDT 2007


Reply to  wbaxter at gmail.com

> If you make cast(ClassType)voidPt check the type then D will have no
> way at all
> to do a reinterpret_cast.  And I also agree that assuming something of
> type C
> is actually type C should be allowed.  So I think the example is just
> bad code.
> If you do a reinterpret_cast then you're taking responsibility into
> your own
> hands.
> But the danger involved would definitely be more apparent if there
> were a more obvious construct for reinterpret casts like
> reinterpret_cast!(T).
> 

is their any reson to cast somthing that isn't a C to type C? Only a few 
reasons some to mind and I'm not shrue any of them should be allowed

Get a call to a derived class to ack on a base class (this won't work anyway 
unless you can force a non v-tbl call, and I don't think you can)
Get somthing that is not an object at all to act like one (again v-tbl calls 
make this realy unlikely)
???

and even if reinterpret_cast is dropped, we will always have unions

template Reinterpret(R)
{
  R Cast(T)(T t)
  {
    union RT{R r;T t;}
    RT rt;
    rt.t=t;
    return rt.r;
  }
}




More information about the Digitalmars-d-bugs mailing list