mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Re-implement move assignments.
The original swap approach leads to potential undefined behavior (reading uninitialized memory) and results in unnecessary copying of data for static storage. Here we pass down the move assignment to the underlying storage. Static storage does a one-way copy, dynamic storage does a swap. Modified the tests to no longer read from the moved-from matrix/tensor, since that can lead to UB. Added a test to ensure we do not access uninitialized memory in a move. Fixes: #2119
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
b8d1857f0d
commit
543e34ab9d
@@ -688,7 +688,7 @@ void big_sparse_triplet(Index rows, Index cols, double density) {
|
||||
typedef Triplet<Scalar,Index> TripletType;
|
||||
std::vector<TripletType> triplets;
|
||||
double nelements = density * rows*cols;
|
||||
VERIFY(nelements>=0 && nelements < NumTraits<StorageIndex>::highest());
|
||||
VERIFY(nelements>=0 && nelements < static_cast<double>(NumTraits<StorageIndex>::highest()));
|
||||
Index ntriplets = Index(nelements);
|
||||
triplets.reserve(ntriplets);
|
||||
Scalar sum = Scalar(0);
|
||||
|
||||
Reference in New Issue
Block a user