[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]

CASTing stones



Abstract:  continuation of inheritance-restricted cast discussion.

   CLASS(T,Heaper) ...
    CLASS(T1,T)
     CLASS(T11,T1)
    CLASS(T2,T)

   T1 * p;

   Let's examine the following expressions:

   a) CAST(T11,p)	// sensible expression, and works if p actually points
   at a kind of T11.

   b) CAST(T,p)  // always works, but should always be unnescesary since
   a T1* should be useable anywhere a T* is.  This could be checked for
   by XLint, but seems unneeded.

This has an affect when p is an argument to an overloaded function.
I'm not sure I approve of this :-).

   d) CAST(T2,p) // can never work unless there has already occurred a
   **SERIOUS** uncaught runtime error in the program.  This is because
   the compile-time-type of p is already T1*, so it would be highly
   exceedingly awfully dangerously strange for it to point at something
   that isn't a kind of T1.  Given single inheritance, anything that
   is a kind of T1 cannot be a kind of T2.

   Granted it isn't a compile time check, but it is a runtime check that
   is always guaranteed to fail.  Therefore, a coverage check *must*
   catch it.

   Unless p == NULL when we do the coverage check.  

   I do think it's possible to figure out an expansion of the CAST macro
   such that only #a and #c compile, but I'm not inclined to try unless
   someone asks me to.

d) is exactly the case I want to catch statically.  Compile-time would
be nice, but xlint would be fine.  How hard is this?

dean