[PATCH] libstdc++: Implement C++23 P2590R2 - Explicit lifetime management
Tomasz Kaminski
tkaminsk@redhat.com
Fri Aug 29 08:12:50 GMT 2025
On Fri, Aug 29, 2025 at 10:04 AM Richard Biener <rguenther@suse.de> wrote:
> On Fri, 29 Aug 2025, Ville Voutilainen wrote:
>
> > On Fri, 29 Aug 2025 at 10:40, Richard Biener <rguenther@suse.de> wrote:
> > > So, is std::start_lifetime_as<T> a thing on readonly objects?
> >
> > Yes. It has a const void* overload. From a language-conceptual
> > perspective, there's nothing odd about creating
> > a const buffer from bit soup and then starting the lifetime of an
> > object of another type in that buffer.
> >
> > From a language perspective it's not a store. It just tells the
> > language that an object of type T resides in that storage.
>
> I fear we have nothing to implement that in all cases at this point
> unless the C++ standard somehow forces provenance on the pointers,
> so that
>
> const short x[8] = {};
> std::start_lifetime_as<const double> (x);
> const double *p = (const double *)x;
>
As far as I understand, per C++ standard p does not point to the long double
object created by start_lifetime_as, so yes I think we are doing what you
mean
by forcing provenance. You could however use pointer returned by
start_lifetime_as.
p = std::start_lifetime_as<const double> (x);
Or launder pointer to x.
std::start_lifetime_as<const double> (x);
p = launder((const double *)x);
... = *p;
>
> is UB.
>
> Richard.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250829/6280b365/attachment.htm>
More information about the Libstdc++
mailing list