C++ Logo

std-proposals

Advanced search

Re: [std-proposals] PROPOSAL: allow implicit conversion from void * to X *

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 20 Sep 2026 15:44:10 -0700
On Sunday, 20 September 2026 15:04:27 Pacific Daylight Time Veгified ✔ via Std-
Proposals wrote:
> Casting explicitly because the element types aren't the same slows down
> development speed and adds no technical benefit.

Except it does add technical benefit.

// two unrelated types and not using the "initial member sequence" exception
// to the rule:
struct S { int i; };
struct T { char *ptr; };

// compiles cleanly in C but is clearly wrong:
// in C++, at least you've had to explicitly choose to do it wrong
struct S s;
void *ptr = &s;
struct T *t = ptr;

https://c.godbolt.org/z/sK7fEoMds

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-09-20 22:44:20