C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::polyhandle (Draft Paper Attached)

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 10 Jun 2025 10:30:26 +0100
On Tue, Jun 10, 2025 at 12:07 AM Oliver Hunt <oliver_at_[hidden]> wrote:
>
> Not sure of the MS implementation, but in stdlibc++ and libc++
> __dynamic_cast assumes that the source type_info and the object has
> already been adjusted to support the path to the target type.


If needed, I'm happy to take the implementation of '__dynamic_cast'
from those libraries and tweak it if needed. But it might work as is,
I'll test and see.


> The fundamental problem that you seem unwilling to understand that the
> c++ type system does not have a polymorphic bottom type, and what you’re
> doing is essentially trying to create one by hacking around assumptions in
> the type system.


I don't know if you're a Star Trek fan, but in Picard's words:

    "Space: the final frontier. These are the voyages of the
     starship Enterprise. Its continuing mission: to explore strange
     new worlds; to seek out new life and new civilizations; to
     boldly go where no man has gone before!"

On the day that I discovered on the GNU g++ compiler that the vtable
pointer is always at address [base + 0x00] in any polymorphic object,
I started to explore. And I started to realise that a lot more is
possible with polymorphic objects than the C++ Standard is letting on.
I'm happy to learn little by little here, and to add more and more to
'polyhandle'. It was actually only yesterday that I started thinking
that maybe I could perform a 'dynamic_cast' from a ' void * '. (Note
that that previous sentence says 'from' instead of 'to').

As you said, C++ hasn't got a polymorphic bottom type. So let's say
that I'm writing a program that uses wxWidgets for some of the
windows, and Qt for some of the other windows. Let's say I have a
global container of all the windows in my program:

    std::vector< polyhandle > g_all_windows;

It would be good if I could, at runtime, check if it's a QWindow or a wxWindow:

    for ( polyhandle p : g_all_windows )
    {
        if ( p.dynamicCast<QWindow> ) DoSomething();
        else if ( p.dynamicCast<wxWidget> ) DoSomethingElse();
    }

I'm taking a look at two ABI's here: The Itanium ABI and the Microsoft
ABI, to see what can be made possible in both.

Received on 2025-06-10 09:30:37