VectorXd a(2); a << 1,2; a = a.segment(0,1); cout << a; outputs: 0 using eval fixes the bug. a.segment(0,1).eval() If this is the expected behaviour it would be useful to have an aliasing assert for this case.
Detecting all cases of aliasing is a very difficult task. Though we do detect a few cases involving transpose, the programmer is supposed to know what he is doing.
Just a side note: I guess this particular example could also be implemented using a.conservativeResize(1); A general suggestion for this problem: If a vector/matrix changes its size during assignment, one could: * allocate a new (temp) vector * assign the expression to the temp vector * swap the vectors * deallocate the temp vector (happens automatically) I guess this would cause virtually no overhead in most cases, OTOH it might be a bad idea, if users rely on this behavior and then a vector accidentally does not change its size ...
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/291.