[LLVMdev] dyn_cast really doesn't like multiple inheritance

Chris Lattner clattner at apple.com
Wed Dec 10 10:28:13 PST 2008


On Dec 9, 2008, at 8:46 PM, Talin wrote:
> Been having a bit of a problem with dyn_cast: Suppose I have a class A
> that inherits from two base classes, both of which support dyn_cast.  
> In
> order to use dyn_cast on A, I need to do a bunch of extra work:

Hi Talin,

I don't really have any experience with using dyn_cast in this sort of  
scenario.

> 1) Since dyn_cast uses reinterpret_cast rather than static_cast, the
> pointer value won't get adjusted by the cast operation, making the
> pointer invalid. I end up having to redefine "cast_convert_val" and
> other parts of the casting machinery for my type, so that it uses
> static_cast.

Is it a problem to just use static_cast everywhere?

> 2) In every class B which derives from A, it seems like I have to  
> have 4
> overloads of 'classof': One for B, one for A, and one for each of A's
> top-most ancestors. Otherwise I get ambiguity errors.
>
> What I am wondering is, is this use case supported? And could it be  
> made
> easier?

I don't think anyone has ever tried it before.  :)  It seems like it  
should work, if you have changes to the machinery that would make it  
more general it would be great to improve Casting.h.

-Chris



More information about the llvm-dev mailing list