Skip to content

Commit

Permalink
Backport Eigen Fix rule-of-three violations
Browse files Browse the repository at this point in the history
This is most of
https://gitlab.com/libeigen/eigen/-/merge_requests/29/diffs (except a
fix for a test that didn't apply cleanly, so I ignored it because we
don't build these tests). New Clang complains about these otherwise.

Change-Id: Id25d1646ecac43bb3a51bece157f52be6e8bfb13
Signed-off-by: Brian Silverman <[email protected]>
  • Loading branch information
Brian Silverman committed Jan 5, 2022
1 parent 312ece3 commit d6ca714
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 14 deletions.
4 changes: 2 additions & 2 deletions third_party/eigen/Eigen/src/Core/ArrayBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ template<typename Derived> class ArrayBase
// inline void evalTo(Dest& dst) const { dst = matrix(); }

protected:
EIGEN_DEVICE_FUNC
ArrayBase() : Base() {}
EIGEN_DEFAULT_COPY_CONSTRUCTOR(ArrayBase)
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(ArrayBase)

private:
explicit ArrayBase(Index);
Expand Down
2 changes: 2 additions & 0 deletions third_party/eigen/Eigen/src/Core/CwiseUnaryView.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class CwiseUnaryViewImpl<ViewOp,MatrixType,Dense>
{
return derived().nestedExpression().outerStride() * sizeof(typename internal::traits<MatrixType>::Scalar) / sizeof(Scalar);
}
protected:
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(CwiseUnaryViewImpl)
};

} // end namespace Eigen
Expand Down
3 changes: 2 additions & 1 deletion third_party/eigen/Eigen/src/Core/DenseBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,12 @@ template<typename Derived> class DenseBase
}

protected:
EIGEN_DEFAULT_COPY_CONSTRUCTOR(DenseBase)
/** Default constructor. Do nothing. */
EIGEN_DEVICE_FUNC DenseBase()
{
/* Just checks for self-consistency of the flags.
* Only do it when debugging Eigen, as this borders on paranoiac and could slow compilation down
* Only do it when debugging Eigen, as this borders on paranoia and could slow compilation down
*/
#ifdef EIGEN_INTERNAL_DEBUGGING
EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, int(IsRowMajor))
Expand Down
5 changes: 5 additions & 0 deletions third_party/eigen/Eigen/src/Core/MapBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ template<typename Derived> class MapBase<Derived, ReadOnlyAccessors>
#endif

protected:
EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase)
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase)

template<typename T>
EIGEN_DEVICE_FUNC
Expand Down Expand Up @@ -294,6 +296,9 @@ template<typename Derived> class MapBase<Derived, WriteAccessors>
// In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base,
// see bugs 821 and 920.
using ReadOnlyMapBase::Base::operator=;
protected:
EIGEN_DEFAULT_COPY_CONSTRUCTOR(MapBase)
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MapBase)
};

#undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS
Expand Down
3 changes: 2 additions & 1 deletion third_party/eigen/Eigen/src/Core/MatrixBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ template<typename Derived> class MatrixBase
EIGEN_MATRIX_FUNCTION_1(MatrixComplexPowerReturnValue, pow, power to \c p, const std::complex<RealScalar>& p)

protected:
EIGEN_DEVICE_FUNC MatrixBase() : Base() {}
EIGEN_DEFAULT_COPY_CONSTRUCTOR(MatrixBase)
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(MatrixBase)

private:
EIGEN_DEVICE_FUNC explicit MatrixBase(int);
Expand Down
2 changes: 2 additions & 0 deletions third_party/eigen/Eigen/src/Core/Transpose.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ template<typename MatrixType> class TransposeImpl<MatrixType,Dense>
{
return derived().nestedExpression().coeffRef(index);
}
protected:
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TransposeImpl)
};

/** \returns an expression of the transpose of *this.
Expand Down
8 changes: 5 additions & 3 deletions third_party/eigen/Eigen/src/Core/TriangularMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
explicit inline TriangularView(MatrixType& matrix) : m_matrix(matrix)
{}

using Base::operator=;
TriangularView& operator=(const TriangularView &other)
{ return Base::operator=(other); }
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TriangularView)

/** \copydoc EigenBase::rows() */
EIGEN_DEVICE_FUNC
Expand Down Expand Up @@ -544,6 +542,10 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularViewImpl<_Mat
template<typename ProductType>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE TriangularViewType& _assignProduct(const ProductType& prod, const Scalar& alpha, bool beta);
protected:
EIGEN_DEFAULT_COPY_CONSTRUCTOR(TriangularViewImpl)
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(TriangularViewImpl)

};

/***************************************************************************
Expand Down
39 changes: 38 additions & 1 deletion third_party/eigen/Eigen/src/Core/util/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,11 +844,48 @@ namespace Eigen {
#endif


/**
* \internal
* \brief Macro to explicitly define the default copy constructor.
* This is necessary, because the implicit definition is deprecated if the copy-assignment is overridden.
*/
#if EIGEN_HAS_CXX11
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS) EIGEN_DEVICE_FUNC CLASS(const CLASS&) = default;
#else
#define EIGEN_DEFAULT_COPY_CONSTRUCTOR(CLASS)
#endif



/** \internal
* \brief Macro to manually inherit assignment operators.
* This is necessary, because the implicitly defined assignment operator gets deleted when a custom operator= is defined.
* With C++11 or later this also default-implements the copy-constructor
*/
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived)
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived) \
EIGEN_INHERIT_ASSIGNMENT_EQUAL_OPERATOR(Derived) \
EIGEN_DEFAULT_COPY_CONSTRUCTOR(Derived)

/** \internal
* \brief Macro to manually define default constructors and destructors.
* This is necessary when the copy constructor is re-defined.
* For empty helper classes this should usually be protected, to avoid accidentally creating empty objects.
*
* Hiding the default destructor lead to problems in C++03 mode together with boost::multiprecision
*/
#if EIGEN_HAS_CXX11
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived) \
EIGEN_DEVICE_FUNC Derived() = default; \
EIGEN_DEVICE_FUNC ~Derived() = default;
#else
#define EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(Derived) \
EIGEN_DEVICE_FUNC Derived() {}; \
/* EIGEN_DEVICE_FUNC ~Derived() {}; */
#endif





/**
* Just a side note. Commenting within defines works only by documenting
Expand Down
3 changes: 3 additions & 0 deletions third_party/eigen/Eigen/src/Core/util/XprHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class no_assignment_operator
{
private:
no_assignment_operator& operator=(const no_assignment_operator&);
protected:
EIGEN_DEFAULT_COPY_CONSTRUCTOR(no_assignment_operator)
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(no_assignment_operator)
};

/** \internal return the index type with the largest number of bits */
Expand Down
3 changes: 3 additions & 0 deletions third_party/eigen/Eigen/src/Geometry/Quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ class QuaternionBase : public RotationBase<Derived, 3>
#ifdef EIGEN_QUATERNIONBASE_PLUGIN
# include EIGEN_QUATERNIONBASE_PLUGIN
#endif
protected:
EIGEN_DEFAULT_COPY_CONSTRUCTOR(QuaternionBase)
EIGEN_DEFAULT_EMPTY_CONSTRUCTOR_AND_DESTRUCTOR(QuaternionBase)
};

/***************************************************************************
Expand Down
6 changes: 0 additions & 6 deletions third_party/eigen/Eigen/src/Geometry/Translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,6 @@ class Translation
/** \returns the inverse translation (opposite) */
Translation inverse() const { return Translation(-m_coeffs); }

Translation& operator=(const Translation& other)
{
m_coeffs = other.m_coeffs;
return *this;
}

static const Translation Identity() { return Translation(VectorType::Zero()); }

/** \returns \c *this with scalar type casted to \a NewScalarType
Expand Down

0 comments on commit d6ca714

Please sign in to comment.