Subject: Re: [Boost-bugs] [Boost C++ Libraries] #11032: boost::offset_ptr needs explicit ctor
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-03-11 20:35:07
#11032: boost::offset_ptr needs explicit ctor
-------------------------------+--------------------------
Reporter: stheophil@⦠| Owner: igaztanaga
Type: Bugs | Status: new
Milestone: To Be Determined | Component: interprocess
Version: Boost 1.57.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+--------------------------
Comment (by igaztanaga):
I can't see the problem. offset_ptr has a constructor that allows
conversions:
{{{
//!Constructor from other offset_ptr. If pointers of pointee types are
//!convertible, offset_ptrs will be convertibles. Never throws.
template<class T2>
offset_ptr( const offset_ptr<T2, DifferenceType, OffsetType,
OffsetAlignment> &ptr
#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
, typename ipcdetail::enable_if_c<
ipcdetail::is_convertible<T2*, PointedType*>::value
&& ipcdetail::offset_ptr_maintains_address<T2,
PointedType>::value
>::type * = 0
#endif
)
: internal(static_cast<OffsetType>
(ipcdetail::offset_ptr_to_offset_from_other<0>(this, &ptr,
ptr.get_offset())))
{}
//!Constructor from other offset_ptr. If pointers of pointee types are
//!convertible, offset_ptrs will be convertibles. Never throws.
template<class T2>
offset_ptr( const offset_ptr<T2, DifferenceType, OffsetType,
OffsetAlignment> &ptr
, typename ipcdetail::enable_if_c<
ipcdetail::is_convertible<T2*, PointedType*>::value
&& !ipcdetail::offset_ptr_maintains_address<T2,
PointedType>::value
>::type * = 0)
: internal(static_cast<OffsetType>
(ipcdetail::offset_ptr_to_offset<0>(static_cast<PointedType*>(ptr.get()),
this)))
{}
}}}
this allows upcasting (from derived to base). Did you mean that offset_ptr
does not support downcasting (from base to derived)? It does that for good
safety reasons as raw pointers don't allow those conversions. Do you want
this to compile?
offset_ptr<Base> pb = ...;
offset_ptr<Derived>pd(p);
whereas this is a compilation error
Base *pb = ...
Derived *pd = pb;
?
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11032#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:18 UTC