https://godbolt.org/z/E3ETx8a88
Is this swapping UB? Am I mutating anything? UBSAN does not report anything.
#include <utility>
struct MyInt
{
MyInt(int ii): i(ii) {}
const int i;
MyInt& operator=(MyInt&& rh)
{
std::swap(const_cast<int&>(i), const_cast<int&>(rh.i));
return *this;
}
};
int main() {
MyInt i0(0);
MyInt i2(2);
i0 = std::move(i2);
return i0.i;
}