Use derived object type in conservative_resize_like_impl

What does this implement/fix?

When calling conservativeResize() on a matrix with DontAlign flag, the temporary variable used to perform the resize should have the same Options as the original matrix to ensure that the correct override of swap is called (i.e. PlainObjectBase::swap(DenseBase<OtherDerived> & other)). Calling the base class swap (i.e in DenseBase) results in assertions errors or memory corruption. This can be demonstrated with this sample program, or with the additional test added to conservative_resize.cpp.

// Tested with g++-7.5
#include <iostream>
#include <Eigen/Eigen>

int main() {
    using Mat =
        Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic, Eigen::DontAlign>;
    Mat mat = Mat::Zero(3, 3);
    mat.conservativeResize(2, 2); // Triggers assertion at DenseBase.h:434
    std::cout << mat(0, 0) << std::endl; // Do not optimize mat away
}

Merge request reports

Loading