Subject: [Boost-bugs] [Boost C++ Libraries] #3022: Automatic conversion from Y* to boost::shared_ptr<Y> with std::pair
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-05-13 14:28:15
#3022: Automatic conversion from Y* to boost::shared_ptr<Y> with std::pair
--------------------------------------------+-------------------------------
Reporter: koelsch_at_[hidden] | Owner: pdimov
Type: Bugs | Status: new
Milestone: | Component: smart_ptr
Version: Boost 1.39.0 | Severity: Problem
Keywords: implicit conversion shared_ptr |
--------------------------------------------+-------------------------------
The assignment of std::pair<X,Y*> to std::pair<X,boost::shared_ptr<Y> >
compiles without warning and implicitly converts a Y* to a
boost::shared_ptr<Y>. I guess this has to do with:
template<class T> class shared_ptr
{
...
template<class Ap>
typename boost::detail::sp_enable_if_auto_ptr< Ap, shared_ptr & >::type
operator=( Ap r )
...
};
This behavior was witnessed under VC2005, VC2008, and gcc4.0.1.
A minimal program demonstrating an evil consequence of this follows:
int main()
{
int i = 2;
boost::shared_ptr<int> j( new int );
//boost::shared_ptr<int> k = &*j; // does not compile
//std::pair<int,boost::shared_ptr<int> > v( i, &*j ); // does not
compile
std::pair<int,boost::shared_ptr<int> > v = std::make_pair( i, &*j );
// However, this compiles
// kabum
}
Regards,
Tobias
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3022> 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:00 UTC