[C++] Inheritance chain enumeration

2009-05-08 Thread Piotr Wyderski
Consider a class hierarchy with single inheritance, as follows:

struct A {

virtual ~A() = default;
}

struct B : public A {

virtual ~B() = default;
};

and

   A* p = new B();

then how can I get the type_info object of the base class of B?
Or, in other words, how do I enumerate the chain of base classes
starting with a pointer to an object? Of course I mean a GCC-internals
-aware way. The following short document:

http://www.codesourcery.com/public/cxx-abi/abi.html#rtti

says that

For similar reasons, we only keep direct base information about
a class type. Indirect base information can be found by chasing
type_info pointers (and care should be taken to determine
ambiguous base class types).

Namely, where do you keep the direct base information about
a class type and what data structures from libstdc++ should I
become familiar with? And the last question: is the format
expected to stable in terms of GCC development?

Best regards
Piotr Wyderski


Re: [C++] Inheritance chain enumeration

2009-05-08 Thread Dave Korn
Piotr Wyderski wrote:
 Namely, where do you keep the direct base information about
 a class type and what data structures from libstdc++ should I
 become familiar with? And the last question: is the format
 expected to stable in terms of GCC development?

  libstdc++-v3/libsupc++/typeinfo.

  Anything defined in the ABI docs should be pretty stable.

  To find the base classes, look at the typeinfo for the class, which will be
abi::__class_type_info or one of its derivatives as specified in the ABI doc
section 2.9.5; the derived types have pointers to (one or more) base class
typeinfos.

cheers,
  DaveK


Re: [C++] Inheritance chain enumeration

2009-05-08 Thread Piotr Wyderski
Dave Korn wrote:

  To find the base classes, look at the typeinfo for the class, which will be
 abi::__class_type_info or one of its derivatives as specified in the ABI doc

It should be __si_class_type_info in my case.
Beautiful! Many thanks Dave :-)

BTW, how do you know what derivate is pointed to by a pointer during
RTTI processing, especially in the context of exception handling? Is there
a type_info for type_info, e.g. an enum?

Best regards
Piotr Wyderski