[eigen] Subtle way to produce bugs when using Block

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I've encountered some (possibly not so?) weird behaviour when keeping
references to blocks:

template <typename X>
void f(const MatrixBase<X>& x)
    typedef typename Block<X, ei_traits<X>::RowsAtCompileTime, 1> col_t;

    for (int i=0; i<x.cols(); ++i)
        //using this line produces strange (undefined) results
        col_t xi(x, i);

        //this is the correct way to do it:
        col_t xi(x.derived(), i);


It was quite hard to hunt down this bug. Apart from that I don't
understand what's happening here, is there a way to prevent the user
from making this mistake?


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/