[cxx-abi-dev] trivial __dynamic_cast fails?
Daniel Wallin
dalwan01 at student.umu.se
Mon Mar 1 18:33:00 UTC 2004
David Baraff wrote:
>> David Baraff <deb at pixar.com> writes:
>>
>>>>
>>> David Abrahams wrote:
>>>
>> <snip>
>>
>> Incidentally, my system stores those offsets as an optimization for
>> all platforms that can handle it (which so far is everything) but if
>> you want to be strict about portable conformance you have to walk
>> through the cast graph.
>>
> I do, so I end up calling the synthesized cast functions several times
> in a single cast.
Maybe irrelevant but...
If you disregard strict conformance or are just interested in casting
up, it is possible to use the exception trick Dave A demonstrated in the
modified boost::any implementation to make the macro usage a little less
verbose and a bit more robust by omitting the bases.
template<class T>
T* cast_up(void* p, std::type_info const& type)
{
try
{
// will throw static_cast<U*>(p), where type = typeid(U)
throw_registered_pointer(p, type);
}
catch (T* converted)
{
return converted;
}
catch (...)
{
return 0;
}
}
// Now we just need to register the throw functions:
struct A {};
REGISTER_CLASS(A);
struct B : A {};
REGISTER_CLASS(B);
It should be possible to use the same trick to generate a cast graph
with byte offsets in the edges, if strict conformance isn't important.
--
Daniel Wallin
More information about the cxx-abi-dev
mailing list