Created attachment 546 [details]
Patch to the move constructor of DenseStorage
I noticed that the move constructor of DenseStorage does not ensure that the moved-from object is in a valid state.
const std::size_t n = 12;
Eigen::MatrixXd source = Eigen::MatrixXd::Zero(n, n);
Eigen::MatrixXd target = std::move(source);
std::cout << source << std::endl;
This program crashes on:
gcc version 4.9.2 (Ubuntu 4.9.2-0ubuntu1~14.04)
passing the compiler flag -std=c++14
The reason is that Eigen::MatrixXd, as well as many other classes, are using DenseStorage to store their data. The move constructor of DenseStorage however has a bug. When DenseStorage A is moved into DenseStorage B, the data pointer of A is correctly set to nullptr, but the number of columns and number of rows is not.
According to the C++ standard, moved-from objects in the standard library
"shall be placed in a valid but unspecified state." (http://stackoverflow.com/a/7028318/1097451) I believe that this is reasonable also for the Eigen library. I made a small patch and tested the above mentioned code. After applying the patch, the code correctly outputs nothing and does not crash.
Thank you for the patch. Applied:
Date: 2015-02-16 09:18:46+00:00
Summary: Bug 956: Fixed bug in move constructors of DenseStorage which caused "moved-from" objects to be in an invalid state.
*** Bug 1157 has been marked as a duplicate of this bug. ***
-- 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/956.