aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/CommaInitializer.h
diff options
context:
space:
mode:
authorGravatar Christoph Hertzberg <chtz@informatik.uni-bremen.de>2014-03-12 13:48:09 +0100
committerGravatar Christoph Hertzberg <chtz@informatik.uni-bremen.de>2014-03-12 13:48:09 +0100
commit2379ccffcb8f1af10f8ed91353d5cb8b3a9a7847 (patch)
tree1c87c011dc016945e40506d66760b4120bddd6c6 /Eigen/src/Core/CommaInitializer.h
parent88aa18df641f8235c88661e41ea128f33d88a8f6 (diff)
bug #755: CommaInitializer produced wrong assertions in absence of ReturnValueOptimization.
Diffstat (limited to 'Eigen/src/Core/CommaInitializer.h')
-rw-r--r--Eigen/src/Core/CommaInitializer.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/Eigen/src/Core/CommaInitializer.h b/Eigen/src/Core/CommaInitializer.h
index 2bbf74b05..70cbfeff5 100644
--- a/Eigen/src/Core/CommaInitializer.h
+++ b/Eigen/src/Core/CommaInitializer.h
@@ -45,6 +45,18 @@ struct CommaInitializer
m_xpr.block(0, 0, other.rows(), other.cols()) = other;
}
+ /* Copy/Move constructor which transfers ownership. This is crucial in
+ * absence of return value optimization to avoid assertions during destruction. */
+ // FIXME in C++11 mode this could be replaced by a proper RValue constructor
+ EIGEN_DEVICE_FUNC
+ inline CommaInitializer(const CommaInitializer& o)
+ : m_xpr(o.m_xpr), m_row(o.m_row), m_col(o.m_col), m_currentBlockRows(o.m_currentBlockRows) {
+ // Mark original object as finished. In absence of R-value references we need to const_cast:
+ const_cast<CommaInitializer&>(o).m_row = m_xpr.rows();
+ const_cast<CommaInitializer&>(o).m_col = m_xpr.cols();
+ const_cast<CommaInitializer&>(o).m_currentBlockRows = 0;
+ }
+
/* inserts a scalar value in the target matrix */
EIGEN_DEVICE_FUNC
CommaInitializer& operator,(const Scalar& s)
@@ -110,7 +122,7 @@ struct CommaInitializer
EIGEN_DEVICE_FUNC
inline XprType& finished() { return m_xpr; }
- XprType& m_xpr; // target expression
+ XprType& m_xpr; // target expression
Index m_row; // current row id
Index m_col; // current col id
Index m_currentBlockRows; // current block height