C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::any::base

From: Rhidian De Wit <rhidiandewit_at_[hidden]>
Date: Fri, 19 Apr 2024 12:15:22 +0200
>
> Of course the guys at Microsoft might know something that I don't know.


That's the point I and others have been trying to make. The compiler
vendors know all this far better than any of us and always will, so it is
more important to focus on "why" than the "how", since the compiler vendors
are the only ones that really care about the "how", and we don't need to
prove anything yet. It's far too early for such a thing.

All the effort you're putting in this is also wasted if the proposal also
never gets accepted! So, maybe first focus on getting the proposal in a
state where it's actually considered to be added, and then maybe this
investigation can be picked up again, if necessary.

Op vr 19 apr 2024 om 12:11 schreef Frederick Virchanza Gotham via
Std-Proposals <std-proposals_at_[hidden]>:

> On Wed, Apr 17, 2024 at 4:13 PM Thiago Macieira wrote:
> >
> > I believe we've already concluded there's no ABI break necessary
> > and the vendor is the ultimate authority anyway.
>
>
> I think it might not be possible without an ABI break on Microsoft.
>
> It turns out that the source code for "__RTDynamicCast" is available here:
>
>
> https://github.com/ojdkbuild/tools_toolchain_vs2017bt_1416/blob/master/VC/Tools/MSVC/14.16.27023/crt/src/vcruntime/rtti.cpp#L205
>
> and it invokes a function called "FindVITargetTypeInstance":
>
>
> https://github.com/ojdkbuild/tools_toolchain_vs2017bt_1416/blob/master/VC/Tools/MSVC/14.16.27023/crt/src/vcruntime/rtti.cpp#L695
>
> And after looking through the code, it looks like it will only work if
> the source object is polymorphic. "FindVITargetTypeInstance" needs
> access to the "RTTICompleteObjectLocator" for the most-derived object
> -- but non-polymorphic types don't have one. Also, the
> "std::type_info" doesn't contain a flag to say whether or not the type
> is polymorphic.
>
> If we forget about the "dynamic_cast" way of doing it, and instead
> focus on the "throw an exception" way of implementing it, then we need
> access to the type's "ThrowInfo" -- but the compiler will only emit
> the "ThrowInfo" if the type is thrown. If the type is never thrown,
> there's no "ThrowInfo". And even if we could guarantee the presence of
> the "ThrowInfo" in the DLL or EXE file, we would need to figure out a
> way of getting the ThrowInfo from the type_info -- I don't see an
> obvious link.
>
> So if you have an "std::any" object, and if you assign a
> non-polymorphic type to it, and then try to get a pointer to a base
> class, there's no way of making it work -- not without adding more
> information to "std::any" and therefore inducing an ABI break.
>
> What we _could_ implement without an ABI break is a member function
> called "base_from_polymorphic", which you would only use if you're
> certain that the contained value is a polymorphic object.
>
> By the way I've also looked through Microsoft's <any> header and I
> don't see anything in there that would make this possible. Of course
> the guys at Microsoft might know something that I don't know.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


-- 
Rhidian De Wit
Software Engineer - Barco

Received on 2024-04-19 10:15:36