aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sparse_basic.cpp
diff options
context:
space:
mode:
authorGravatar Antonio Sanchez <cantonios@google.com>2021-03-05 12:54:26 -0800
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2021-03-10 16:55:20 +0000
commit543e34ab9dee6004337b7ad912417eb91bf4a0b9 (patch)
treef250fa260325479d4006f0dec77f5ce2bdc009c5 /test/sparse_basic.cpp
parentb8d1857f0d87475016b5c16a6a235efa1fd5e9b5 (diff)
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
Diffstat (limited to 'test/sparse_basic.cpp')
-rw-r--r--test/sparse_basic.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index f7ad930e9..9453111b7 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -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);