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];
auto x_left_atomic = std::atomic_ref<int16_t>(x_left);
auto x_right_atomic = std::atomic_ref<int16_t>(x_right);
// Atomic loads have to read-from a store
// These both read-from line 11 but they read different things???
int16_t left = x_left_atomic.load(std::memory_order_relaxed);
int16_t right = x_right_atomic.load(std::memory_order_relaxed);
return std::pair<int16_t, int16_t>(left, right);
}
std::int32_t mixed_atomicity() {
int32_t x = 0;
{
auto x_atomic = std::atomic_ref<int32_t>(x);
x_atomic.store(42, std::memory_order_relaxed);
// atomic_ref lifetime ends so we can use x again
}
// Obviously reading 42 is sane here, but there is no codified semantics
// governing non-atomically reading an atomic location in any circumstance
int32_t read = x;
return read;
}