From 36448c9e287935b8c408791bf88b2907292d6c80 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Tue, 23 Sep 2014 14:28:23 +0200 Subject: Make constructors explicit if they could lead to unintended implicit conversion --- Eigen/src/Core/TriangularMatrix.h | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'Eigen/src/Core/TriangularMatrix.h') diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 36f04a5e8..36bbd46e1 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -211,8 +211,9 @@ template class TriangularView IsVectorAtCompileTime = false }; + // FIXME This, combined with const_cast_derived in transpose() leads to a const-correctness loophole EIGEN_DEVICE_FUNC - inline TriangularView(const MatrixType& matrix) : m_matrix(matrix) + explicit inline TriangularView(const MatrixType& matrix) : m_matrix(matrix) {} using Base::operator=; @@ -229,32 +230,36 @@ template class TriangularView EIGEN_DEVICE_FUNC NestedExpression& nestedExpression() { return *const_cast(&m_matrix); } + typedef TriangularView ConjugateReturnType; /** \sa MatrixBase::conjugate() */ EIGEN_DEVICE_FUNC - inline TriangularView conjugate() - { return m_matrix.conjugate(); } + inline ConjugateReturnType conjugate() + { return ConjugateReturnType(m_matrix.conjugate()); } /** \sa MatrixBase::conjugate() const */ + EIGEN_DEVICE_FUNC - inline const TriangularView conjugate() const - { return m_matrix.conjugate(); } + inline const ConjugateReturnType conjugate() const + { return ConjugateReturnType(m_matrix.conjugate()); } + typedef TriangularView AdjointReturnType; /** \sa MatrixBase::adjoint() const */ EIGEN_DEVICE_FUNC - inline const TriangularView adjoint() const - { return m_matrix.adjoint(); } + inline const AdjointReturnType adjoint() const + { return AdjointReturnType(m_matrix.adjoint()); } - /** \sa MatrixBase::transpose() */ + typedef TriangularView,TransposeMode> TransposeReturnType; + /** \sa MatrixBase::transpose() */ EIGEN_DEVICE_FUNC - inline TriangularView,TransposeMode> transpose() + inline TransposeReturnType transpose() { EIGEN_STATIC_ASSERT_LVALUE(MatrixType) - return m_matrix.const_cast_derived().transpose(); + return TransposeReturnType(m_matrix.const_cast_derived().transpose()); } /** \sa MatrixBase::transpose() const */ EIGEN_DEVICE_FUNC - inline const TriangularView,TransposeMode> transpose() const + inline const TransposeReturnType transpose() const { - return m_matrix.transpose(); + return TransposeReturnType(m_matrix.transpose()); } template @@ -556,7 +561,7 @@ template typename MatrixBase::template TriangularViewReturnType::Type MatrixBase::triangularView() { - return derived(); + return typename TriangularViewReturnType::Type(derived()); } /** This is the const version of MatrixBase::triangularView() */ @@ -565,7 +570,7 @@ template typename MatrixBase::template ConstTriangularViewReturnType::Type MatrixBase::triangularView() const { - return derived(); + return typename ConstTriangularViewReturnType::Type(derived()); } /** \returns true if *this is approximately equal to an upper triangular matrix, -- cgit v1.2.3