C++ Logo

std-discussion

Advanced search

Re: Is it valid use reinterpret_cast to form pointer to object?

From: Thiago Macieira <thiago_at_[hidden]>
Date: Mon, 31 Jul 2023 23:45:49 -0700
On Monday, 31 July 2023 22:57:53 PDT Lénárd Szolnoki via Std-Discussion wrote:
> The need for launder is much more clear regarding compiler optimisations if
> the same storage is used to hold different objects during its lifetime. But
> you technically need it when the storage only ever holds a single object.

Right. Which is also the case that shows that std::start_lifetime_as can't be
idempotent.

And since I am arguing that the called function did start the object's
lifetime (in C or via malloc() or memcpy()), then (re)starting the lifetime of
the object is very likely wrong.

The way I see it, either we accept that C can start lifetime of some C++
objects, or we put std::start_lifetime_as everywhere there's a language
transition and you must know whether the other side is implemented in C++ or
not. The latter case is an obvious non-starter.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-08-01 06:45:51