I want to use an auto reference to a block of an eigen matrix:
MatrixXf a = MatrixXf::Random(20,20);
auto& a_block = a.block(2, 3, 4, 5);
MSVC compiles and works well, while GCC does not compile, if the reference is not constant. See the example here
The error from GCC is
[x86-64 gcc 8.3 #2] error: cannot bind non-const lvalue reference of type 'Eigen::Block<Eigen::Matrix<float, -1, -1>, -1, -1, false>&' to an rvalue of type 'Eigen::DenseBase<Eigen::Matrix<float, -1, -1> >::FixedBlockXpr<-1, -1>::Type' {aka 'Eigen::Block<Eigen::Matrix<float, -1, -1>, -1, -1, false>'}
Is this a bug or should it be expected behaviour? Is there an elegant workaround for GCC?
Here's the linked code of the reproducible example (for archieve):
#include <Eigen/Dense>
using namespace Eigen;
void foo(MatrixXf& a)
{
auto& a_block = a.block(2, 3, 4, 5);
a_block = MatrixXf::Random(4,5);
}