Move assignment swaps even for non-dynamic storage
Matrix move assignment is implemented as
Matrix& operator=(Matrix&& other)
{
other.swap(*this);
return *this;
}
which makes perfect sense when swapping is only swapping the pointer. But for the inline storage case, this ends up copying (swapping) the values from this
back to other
which we don't care about.
This can trigger clang-analyzer warnings about assigning garbage values, for example
Eigen::Matrix3d uninit; // values not initialized
Eigen::Matrix3d ones = {1.0, 1.0, 1.0};
uninit = std::move(ones); // this copies / swaps the uninitialized values we don't care about from uninit back to ones
Edited by Daniel Vollmer