From 89cda8c24474f2eddedc9486a0b908a49635352f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkovsky@mmg.fjfi.cvut.cz>
Date: Sat, 15 Jan 2022 19:07:27 +0100
Subject: [PATCH] Fixed copy-constructor in SparseMatrix

It cannot be default, because the internal view would still point to the
original matrix.
---
 src/TNL/Matrices/SparseMatrix.h   |  2 +-
 src/TNL/Matrices/SparseMatrix.hpp | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/TNL/Matrices/SparseMatrix.h b/src/TNL/Matrices/SparseMatrix.h
index f4ed3244be..c8d8eff28f 100644
--- a/src/TNL/Matrices/SparseMatrix.h
+++ b/src/TNL/Matrices/SparseMatrix.h
@@ -181,7 +181,7 @@ class SparseMatrix : public Matrix< Real, Device, Index, RealAllocator >
        *
        * \param matrix is the source matrix
        */
-      SparseMatrix( const SparseMatrix& matrix1 ) = default;
+      explicit SparseMatrix( const SparseMatrix& matrix );
 
       /**
        * \brief Move constructor.
diff --git a/src/TNL/Matrices/SparseMatrix.hpp b/src/TNL/Matrices/SparseMatrix.hpp
index 33c9296f2e..48269db058 100644
--- a/src/TNL/Matrices/SparseMatrix.hpp
+++ b/src/TNL/Matrices/SparseMatrix.hpp
@@ -27,6 +27,24 @@ SparseMatrix( const RealAllocatorType& realAllocator,
 {
 }
 
+template< typename Real,
+          typename Device,
+          typename Index,
+          typename MatrixType,
+          template< typename, typename, typename > class Segments,
+          typename ComputeReal,
+          typename RealAllocator,
+          typename IndexAllocator >
+SparseMatrix< Real, Device, Index, MatrixType, Segments, ComputeReal, RealAllocator, IndexAllocator >::
+SparseMatrix( const SparseMatrix& matrix )
+: BaseType( matrix ),
+  columnIndexes( matrix.columnIndexes ),
+  segments( matrix.segments ),
+  indexAllocator( matrix.indexAllocator ),
+  view( this->getView() )
+{
+}
+
 template< typename Real,
           typename Device,
           typename Index,
-- 
GitLab