Modify

Opened 7 years ago

Closed 7 years ago

#5216 closed Bugs (fixed)

boost::hash<boost::shared_ptr<T>> Returns Only Two Values

Reported by: Rob Stewart <robert.stewart@…> Owned by: Peter Dimov
Milestone: To Be Determined Component: smart_ptr
Version: Boost 1.44.0 Severity: Problem
Keywords: shared_ptr hash Cc:

Description

The attached program demonstrates that a null shared_ptr<int> produces a hash value of zero and that (ostensibly) all non-null instances produce a hash value of one.

Attachments (1)

bad_hash.cpp (708 bytes) - added by Rob Stewart <robert.stewart@…> 7 years ago.
Bug demonstration program

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by Rob Stewart <robert.stewart@…>

Attachment: bad_hash.cpp added

Bug demonstration program

comment:1 Changed 7 years ago by Rob Stewart <robert.stewart@…>

Defining BOOST_HASH_NO_IMPLICIT_CASTS produces a static assertion failure which is better than the silent misbehavior.

The following makes things work, regardless of whether BOOST_HASH_NO_IMPLICIT_CASTS is defined:

namespace boost
{
   template <class T>
   std::size_t
   hash_value(boost::shared_ptr<T> const & _ptr)
   {
      return boost::hash_value(_ptr.get());
   }
}

comment:2 Changed 7 years ago by Peter Dimov

(In [69260]) Add hash_value for shared_ptr; prevents hash_value( bool ) from being used. Refs #5216.

comment:3 Changed 7 years ago by Peter Dimov

Status: newassigned

comment:4 Changed 7 years ago by Peter Dimov

Resolution: fixed
Status: assignedclosed

(In [70440]) Merge [69260] to release. Fixes #5216.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Peter Dimov.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.