[LLVMdev] dyn_cast really doesn't like multiple inheritance

Talin viridia at gmail.com
Tue Dec 9 20:46:47 PST 2008


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:

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.

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?

-- Talin




More information about the llvm-dev mailing list