bug #1074: forbid the creation of PlainObjectBase object by making its ctor protected

This commit is contained in:
Gael Guennebaud 2015-12-09 15:47:08 +01:00
parent 1257fbd2f9
commit dc73430d4b

View File

@ -449,6 +449,10 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
return Base::operator=(func); return Base::operator=(func);
} }
// Prevent user from trying to instantiate PlainObjectBase objects
// by making all its constructor protected. See bug 1074.
protected:
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE PlainObjectBase() : m_storage() EIGEN_STRONG_INLINE PlainObjectBase() : m_storage()
{ {
@ -495,17 +499,6 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
// EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED
} }
/** \copydoc MatrixBase::operator=(const EigenBase<OtherDerived>&)
*/
template<typename OtherDerived>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE Derived& operator=(const EigenBase<OtherDerived> &other)
{
_resize_to_match(other);
Base::operator=(other.derived());
return this->derived();
}
/** \sa PlainObjectBase::operator=(const EigenBase<OtherDerived>&) */ /** \sa PlainObjectBase::operator=(const EigenBase<OtherDerived>&) */
template<typename OtherDerived> template<typename OtherDerived>
EIGEN_DEVICE_FUNC EIGEN_DEVICE_FUNC
@ -538,6 +531,19 @@ class PlainObjectBase : public internal::dense_xpr_base<Derived>::type
other.evalTo(this->derived()); other.evalTo(this->derived());
} }
public:
/** \copydoc MatrixBase::operator=(const EigenBase<OtherDerived>&)
*/
template<typename OtherDerived>
EIGEN_DEVICE_FUNC
EIGEN_STRONG_INLINE Derived& operator=(const EigenBase<OtherDerived> &other)
{
_resize_to_match(other);
Base::operator=(other.derived());
return this->derived();
}
/** \name Map /** \name Map
* These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects, * These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects,
* while the AlignedMap() functions return aligned Map objects and thus should be called only with 16-byte-aligned * while the AlignedMap() functions return aligned Map objects and thus should be called only with 16-byte-aligned