bug #1381: fix sparse.diagonal() used as a rvalue.
The problem was that is "sparse" is not const, then sparse.diagonal() must have the
LValueBit flag meaning that sparse.diagonal().coeff(i) must returns a const reference,
const Scalar&. However, sparse::coeff() cannot returns a reference for a non-existing
zero coefficient. The trick is to return a reference to a local member of
evaluator<SparseMatrix>.
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index 208a66f..91b7cb3 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -485,6 +485,10 @@
SparseMatrixType m2(rows, cols);
initSparse<Scalar>(density, refMat2, m2);
VERIFY_IS_APPROX(m2.diagonal(), refMat2.diagonal().eval());
+ DenseVector d = m2.diagonal();
+ VERIFY_IS_APPROX(d, refMat2.diagonal().eval());
+ d = m2.diagonal().array();
+ VERIFY_IS_APPROX(d, refMat2.diagonal().eval());
VERIFY_IS_APPROX(const_cast<const SparseMatrixType&>(m2).diagonal(), refMat2.diagonal().eval());
initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag);