[cxx-abi-dev] trivial __dynamic_cast fails?
David Baraff
deb at pixar.com
Fri Feb 27 21:19:01 UTC 2004
Begin forwarded message:
> From: Daveed Vandevoorde <daveed at edg.com>
> Date: February 27, 2004 1:10:18 PM PST
> To: cxx-abi-dev at codesourcery.com
> Cc: David Baraff <deb at pixar.com>, David Abrahams
> <dave at boost-consulting.com>
> Subject: Re: [cxx-abi-dev] trivial __dynamic_cast fails?
>
>
> On Feb 27, 2004, at 12:36 PM, Mark Mitchell wrote:
>
>> David Baraff wrote:
>>
>>> I'm playing around with the __cxxabiv1::__dynamic_cast() function.
>>> It
>>> works as I would expect, with one exception.
>>
>> The ABI document does not require that __dynamic_cast perform a
>> derived-to-base cast. Those __dynamic_cast operations that can
>> actually be performed statically by the compiler must be performed
>> statically by the compiler -- the runtime library does not expect to
>> be called in that situation.
>
Please note that Mark Mitchell already pointed me in the right
direction, though it shifts a lot of implementation burden to me. I
can use the base_type_info to compute the address shift as I chain
upward from derived to base, which is all I'm really after in this
case.
So the functionality I require is in fact exposed by this very nicely
crafted API.
But please, feel free to make __dynamic_cast do *all* the work, so I
can write less code... :)
> Indeed. However, it is not the first time I
> encounter the desire to be able to do this
> sort of thing. Since the ABI specs do not
> currently say what __dynamic_cast should do
> in the cases that the compiler handles alone,
> I don't think there would be a significant
> backward compatibility issue in trying to
> support a useful design technique. If it
> can be done within the framework of the
> existing RTTI structures, I think it would
> be worth "upgrading" __dynamic_cast to
> address this.
It obviously can -- currently it returns NULL. So instead, it can
certainly do the computation outlined above. (I say obviously without
bothering to consider whether there might be tricky boundary cases ---
I mean it seems like it obviously could, to a layman such as myself...)
>
> There has been occasional talk among WG21/
> J16 actives about adding a facility like
> what David B. is looking for, but so far
> no concrete proposals. I'm going to CC
> David Abrahams who mentioned the desire
> for this once. Perhaps he has some insight
> into how widespread the need for this is.
Here's a biggy. Consider the boost::any class. Currently, if it holds
a Derived* and you ask it for a Base*, I think it says "no can do."
Imagine if it could actually say "yes, I can give you back a Base*",
because it could dynamically look up the parent chain, and do the
address shift.
That would make boost::any a heck of a lot more useful than it is today.
>
> Daveed
>
More information about the cxx-abi-dev
mailing list