On Fri, Aug 29, 2025 at 08:48:02AM +0200, Tomasz Kaminski wrote:
> >From recent discussions, my understand was that this function can be
> implemented purely in library as:
> return launder(static_cast<T*>(memmove(p, p, sizeof(T))));
It can't, we optimize memmove(p,p,whatever) away pretty much instantly,
so all it ends up with is __builtin_launder (and later comparison against
the original pointer with the launder return can get us back to the original
pointer).
And, if we didn't, then it wouldn't work for the const case and would create
data races where there shouldn't be one otherwise.
Or is
struct S { int a[2]; };
struct T { long long b; };
const struct S s[2] = { { 1, 2 }, { 3, 4 } };
long long
foo ()
{
auto p = std::start_lifetime_as_array<T> (reinterpret_cast<const void *>
(&s[0]), 2);
return p[0].b + p[0].c;
}
instead for some reason?
Or multiple threads doing start_lifetime_as on the same block of memory
concurrently?
My understanding is that it is as if it is a store but not really.
Jakub