*********How to get during compile time the base class of casted C++ object inside static_cast<> and dynamic_cast<> and the pointer of the casted object

I want to detect bad casts in C++ code by using the Clang
compiler. The approach is similar to what Caver and TypeSan do but
without using the compiler-rt.

Caver and TypeSan:

For example if I have the following C++ code snippet where I want to
cast object b into
object D.

D* obj = static_cast<D*>(b);

from where (inside Clang, LTO, thinLTO, etc.) can I get the base class
of D and the base class ob b. Is this
available in the Clang compiler or LTO?

Also, if b is an object of a virtual Class (class with inherited or its
own virtual functions) can I get its virtual pointer at compile time
by using the LTO?

I found out that in CodeGen/CGExpr.cpp the explicit case "BaseToDerived" is
handled and you can retrieve TypeSourceInfo using the function
getTypeInfoAsWritten(). It seems that this information is enough to get
the exact type of this cast at compile-time and should also work for
Template programming, as my, understanding is that Clang should have
abstracted the code into, specific types at this point.

Am I wrong here?

Is there any case where the type of the objects used inside the cast
not known at compile time? Can the,
'real' type be hidden behind a pointer?

Hi Paul,

It is the 4th time in two weeks that you repost the exact same two emails, that’s a bit high repost rate for the mailing-list, especially considering that you already got answers that you ignored previously:

Adding an alternate email in case you didn’t receive previous emails.

Hi Mehdi,

thanks a lot for your email. Actually I was disappointed by the fact that I was not able to get a useful answer to my two questions.
As I observed that the questions move down along the list with time passing I decided to re-post them in the hope that the questions
will have a better visibility.

Could you help me with the two questions? Finding an expert in this area would be of great help. Do you think the questions are not well stated.

Regards
Paul

Hi Mehdi,

thanks a lot for your email. Actually I was disappointed by the fact that I was not able to get a useful answer to my two questions.
As I observed that the questions move down along the list with time passing I decided to re-post them in the hope that the questions
will have a better visibility.

I don’t think we have a guideline on this, but reposting more than once a week seems too much.

Could you help me with the two questions? Finding an expert in this area would be of great help. Do you think the questions are not well stated.

As mentioned in my previous email, you got two answers to your previous questions that went apparently ignored. A good starting point would be to iterate from there. Reposting the same question means that someone may spend time answering the same thing as the answer you already got because your repost does not maintain the threading / history of the discussion.

Hi Mehdi,

Ok. I see. I will keep this in mind and agree with your suggestions. I will try to start a thread from the currently posted questions.

Regards
Paul

If the answers don't match your expected direction, it is often a sign
that your question was misunderstood and needs clarification. A good
starting point would be to reply to your original mail and restate the
question or add more context.

Joerg