On Tue, Jul 8, 2025 at 9:57 AM Yongwei Wu via Std-Discussion <std-discussion@lists.isocpp.org> wrote:
Assume I am working on a little-endian machine only. Is the following
code undefined behaviour?
uint32_t data = 0x40400000;
auto f = *std::start_lifetime_as<float>(&data);
It's fine as long as `sizeof(float) <= sizeof(uint32_t)`. See https://eel.is/c++draft/obj.lifetime#2
Is it not also the case that implicit object creation requires
that the storage be provided by an object that meets the provides
storage requirements? https://eel.is/c++draft/intro.object#3.
I thought it was required, but I'm unable to find clear wording
now.
If it is not, is the data variable still accessible now?
No. The `data` object's lifetime has ended because its storage has been reused. https://eel.is/c++draft/basic.life#2.5
And the old object is not one that is transparently replaceable
by the new object. https://eel.is/c++draft/basic.life#10
Tom.
Best regards,
Yongwei
--
Yongwei Wu
URL: http://wyw.dcweb.cn/
--
Std-Discussion mailing list
Std-Discussion@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
--
Brian Bi