C++ Logo

std-proposals

Advanced search

Re: [std-proposals] dynamic_cast<void*>(void*)

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 26 Feb 2024 12:59:24 +0000
On Mon, Feb 26, 2024 at 11:53 AM Frederick Virchanza Gotham wrote:
>
> Just now I tried the same code on Microsoft Visual Studio 2022, and it
> crashes. I'm not sure if it's also possible with the Microsoft ABI --
> I'll read up on the Microsoft layout of vtables and try code it.


I'm starting to think that this might not be possible with the
Microsoft compiler, because the pointer to the vtable might not be
located at the beginning of the object. I used the command line
option:

    /d1reportSingleClassLayoutDerived1

and it showed me the following:

      class Derived1 size(80):
      +---
      0 | +--- (base class Base1)
      0 | | i
      4 | | j
      8 | | k
      | +---
      6 | {vbptr}
      4 | a
      8 | b
      2 | c
      | <alignment member> (size=4)
      +---

So even though 'Derived1' is a polymorphic class, it does not start
with a pointer to a vtable. So maybe 'dynamic_cast<void*>(void*)'
isn't possible on the Microsoft compiler. I'll send an email to Lukasz
Lipski and Ofek Shilon to see if there's any way around this (they've
both written tutorials about Microsoft's implementation of
virtualness).

Received on 2024-02-26 12:59:37