Subject: [Boost-bugs] [Boost C++ Libraries] #1444: scoped_ptr::operator== should be equivalent to a.get()==b.get(), but is currently !!a==!!b
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2007-11-15 16:26:49
#1444: scoped_ptr::operator== should be equivalent to a.get()==b.get(), but is
currently !!a==!!b
----------------------------------------------+-----------------------------
Reporter: Geoffrey Irving <irving_at_[hidden]> | Type: Bugs
Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.34.1
Severity: Problem | Keywords:
----------------------------------------------+-----------------------------
scoped_ptr<T> does not define an explicit operator==, so an equality test
between two
of them falls back to using the implicit conversion to bool. Here's a
program illustrating
the bug:
{{{
#include <boost/scoped_ptr.hpp>
int main()
{
boost::scoped_ptr<int> a1(new int),a2(new int);
BOOST_ASSERT(a1!=a2); // fails
BOOST_ASSERT(!(a1==a2)); // fails
}
}}}
This is a significant bug, since it results in silent failures when
converting programs
using normal pointers to scoped_ptr. Adding definitions for operator==
and operator!=
fixes the problem:
{{{
template<class T> inline bool operator==(const scoped_ptr<T>& p, const
scoped_ptr<T>& q)
{
return p.get()==q.get();
}
template<class T> inline bool operator!=(const scoped_ptr<T>& p, const
scoped_ptr<T>& q)
{
return p.get()!=q.get();
}
}}}
I verified that the comparison operators (e.g., <), do not compile, which
is fine.
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1444>
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:49:57 UTC