[cfe-dev] Using isa & co with custom class hierarchy

Jan Bierbaum s3306700 at inf.tu-dresden.de
Wed Aug 25 08:02:31 PDT 2010


Hi!

I hope I'm not too OT with that question, but Clang makes extensive use
of this mechanism so maybe somebody can help me.

LLVM provides isa<>, cast<> and so on. Recently I tried to make use of
this for my own class hierarchy, but failed.

>From the documentation and examples in Clang's code I figured that the
only thing to do was add a static method 'classof' to any involved class
with a parameter that will match any parent class. Then inside this
method do any checks necessary and return 'true' if the current instance
is indeed of the type given.

But when I do this I get 'true' for any 'isa<>' I try!?

Attached is a small example that outputs the following:

| $ ./a.out
| isa<A>(a) = 1
| isa<B>(a) = 1
| isa<B>(b) = 1
| isa<A>(b) = 1

What I would expect instead is the second line to yield false/0, since a
is an instance of class A which "is" no B.

Can somebody please give me a hint on what I'm doing wrong?


Regards, Jan.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: isa.cpp
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100825/105c7192/attachment.ksh>


More information about the cfe-dev mailing list