On Fri, Aug 29, 2025 at 10:04 AM Richard Biener <rguent...@suse.de> wrote:

> On Fri, 29 Aug 2025, Ville Voutilainen wrote:
>
> > On Fri, 29 Aug 2025 at 10:40, Richard Biener <rguent...@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.
>
>

Reply via email to