diff options
author | Antonio Sanchez <cantonios@google.com> | 2021-04-21 15:45:31 -0700 |
---|---|---|
committer | Rasmus Munk Larsen <rmlarsen@google.com> | 2021-04-22 18:45:19 +0000 |
commit | d213a0bcea2344aa3f6c9856da9f5b2a26ccec25 (patch) | |
tree | 2cc3668db7d8928455a0e051d6373873ba4a316e /test/rvalue_types.cpp | |
parent | 85a76a16ea835fcfa7d4c185a338ae2aef9a272a (diff) |
DenseStorage safely copy/swap.
Fixes #2229.
For dynamic matrices with fixed-sized storage, only copy/swap
elements that have been set. Otherwise, this leads to inefficient
copying, and potential UB for non-initialized elements.
Diffstat (limited to 'test/rvalue_types.cpp')
-rw-r--r-- | test/rvalue_types.cpp | 31 |
1 files changed, 1 insertions, 30 deletions
diff --git a/test/rvalue_types.cpp b/test/rvalue_types.cpp index c20a32f79..2c9999ce8 100644 --- a/test/rvalue_types.cpp +++ b/test/rvalue_types.cpp @@ -13,41 +13,12 @@ #if EIGEN_HAS_CXX11 #include "MovableScalar.h" #endif +#include "SafeScalar.h" #include <Eigen/Core> using internal::UIntPtr; -// A Scalar that asserts for uninitialized access. -template<typename T> -class SafeScalar { - public: - SafeScalar() : initialized_(false) {} - SafeScalar(const SafeScalar& other) { - *this = other; - } - SafeScalar& operator=(const SafeScalar& other) { - val_ = T(other); - initialized_ = true; - return *this; - } - - SafeScalar(T val) : val_(val), initialized_(true) {} - SafeScalar& operator=(T val) { - val_ = val; - initialized_ = true; - } - - operator T() const { - VERIFY(initialized_ && "Uninitialized access."); - return val_; - } - - private: - T val_; - bool initialized_; -}; - #if EIGEN_HAS_RVALUE_REFERENCES template <typename MatrixType> void rvalue_copyassign(const MatrixType& m) |