Date: Thu, 26 May 2022 13:02:28 +0500
> std::pair<int16_t, int16_t> mixed_size() {
> int32_t x = 0;
>
> {
> auto x_atomic = std::atomic_ref<int32_t>(x);
> x_atomic.store(0xabbafafa, std::memory_order_relaxed);
> // atomic_ref lifetime ends so we can use x again
> }
>
> auto x_parts = reinterpret_cast<int16_t*>(&x);
> int16_t& x_left = x_parts[0];
> int16_t& x_right = x_parts[1];
The last two lines have undefined behavior.
> int32_t x = 0;
>
> {
> auto x_atomic = std::atomic_ref<int32_t>(x);
> x_atomic.store(0xabbafafa, std::memory_order_relaxed);
> // atomic_ref lifetime ends so we can use x again
> }
>
> auto x_parts = reinterpret_cast<int16_t*>(&x);
> int16_t& x_left = x_parts[0];
> int16_t& x_right = x_parts[1];
The last two lines have undefined behavior.
Received on 2022-05-26 08:02:35