C++ Logo


Advanced search

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

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Mon, 26 Feb 2024 12:21:24 +0000
You can't dynamic cast something to void* because nothing inherits from void.
void is not a type, you can't have an object of type void, it's a place holder. dynamic_cast makes absolutely no sense, neither does static_cast.

From: Std-Proposals <std-proposals-bounces_at_[hidden]> on behalf of Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]>
Sent: Monday, February 26, 2024 12:53:20 PM
To: std-proposals_at_[hidden] <std-proposals_at_lists.isocpp.org>
Cc: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Subject: Re: [std-proposals] dynamic_cast<void*>(void*)

On Mon, Feb 26, 2024 at 11:43 AM Andrey Semashev wrote:
> dynamic_cast from void* to void* is currently well-defined.

I don't see that in the C++ Standard. The following 4 compilers complain:

    the operand of a pointer dynamic_cast must be a pointer to a
complete class type
GNU g++
    cannot 'dynamic_cast' 'v' (of type 'void* const') to type 'void*'
(source is not a pointer to class)
LLVM clang++
    'void' is not a class type
Intel ICX
    'void' is not a class type

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.
Std-Proposals mailing list

Received on 2024-02-26 12:21:27