From 543e34ab9dee6004337b7ad912417eb91bf4a0b9 Mon Sep 17 00:00:00 2001 From: Antonio Sanchez Date: Fri, 5 Mar 2021 12:54:26 -0800 Subject: 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 --- test/sparse_basic.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/sparse_basic.cpp') 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 TripletType; std::vector triplets; double nelements = density * rows*cols; - VERIFY(nelements>=0 && nelements < NumTraits::highest()); + VERIFY(nelements>=0 && nelements < static_cast(NumTraits::highest())); Index ntriplets = Index(nelements); triplets.reserve(ntriplets); Scalar sum = Scalar(0); -- cgit v1.2.3