C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Use the exception system to check for bases at runtime

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 06 Apr 2024 21:54:43 -0700
On Saturday 6 April 2024 13:04:24 PDT Frederick Virchanza Gotham via Std-
Proposals wrote:
> Earlier this week, I wrote:
> > Before I go any further with this, I have to see if it can be
> > implemented with the Microsoft compiler. Because if I can get it
> > working with Microsoft, then I'll have the top 4 compilers.
>
> Implementing this on the Microsoft compiler without compiler support
> has been tricky.
>
> On the GNU, LLVM and Intel compilers, you only need a 'type_info' in
> order to throw and catch an exception. However on Microsoft, when you
> throw an exception, they have a 'ThrowInfo' struct which contains an
> array of pointers to 'type_info' structs for all the base classes of
> the type being thrown.

Then implement the casting functionality without attempting to throw. If
dynamic_cast can do it, then the casting seems possible. I don't see why
throwing needs to be involved at all.

You have to prove only that it is possible, not that your solution works. If
the compiler definitely has the information, then the compiler can implement
the paper once you write it and gets accepted into the language.

> So then inside my 'base' function, I convert the supplied 'type_info'
> to a 'ThrowInfo', I iterate throw all the contained type_info's, and
> if there's a match, I adjust the 'this' pointer and return it. In
> order to adjust the 'this' pointer, I use the "_PMD::mdisp" field
> however I'm not sure if this is correct (I see that there's also a
> 'pdisp' and a 'vdisp' but I don't know what's what).


Your "base" functionality is a means to an end. Drop it.

Focus on the end: casting a void pointer plus typeinfo to a compile-time
specified type. Maybe even void pointer and typeinfo to a void pointer of a
given typeinfo.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Principal Engineer - Intel DCAI Cloud Engineering

Received on 2024-04-07 04:54:48