Opened 7 years ago

Closed 7 years ago

#5191 closed Bugs (fixed)

intrusive unordered_set: const version of iterator_to() won't compile

Reported by: paul.d.rose@… Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: intrusive
Version: Boost 1.45.0 Severity: Problem
Keywords: Cc:


Discovered on 1_38_0 using g++ 4.3.2 on SuSE Linux Reproduced on 1_45_0 using g++ 4.2.1 on Macintosh (XCode)

Reproduce by adding

   MyClass const &cr = values[0];

to the bottom of the documentation example for unordered_set.

iterator_to is trying to construct a const_iterator from a const bucket iterator, but this isn't supported by the iterator constructor. That lack of support by the iterator constructor seems to be by design (the internal bucket iterator is a non-const slist iterator).

It appears that iterator_to is trying to call the non-cost priv_value_to_node by casting away the constness of the value param, but since the 'this' pointer is still const, the const version of priv_value_to_node is called instead.

Removing the const_cast of hte value param, and adding a const_cast to the return value of priv_value_to_node seems to fix things just fine in 1_38_0.

I tried changing:

  return const_iterator(bucket_type::s_iterator_to(
    priv_value_to_node(const_cast<reference>(value))), this);


  return const_iterator(bucket_type::s_iterator_to(
    const_cast<node &>(priv_value_to_node(value))), this);

in iterator_to in file boost/intrusive/hashtable.hpp (near line 1682 in 1_38_0) and it seems to be working just fine.

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by Ion Gaztañaga

Resolution: fixed
Status: newclosed

Fixed in Boost 1.47

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Ion Gaztañaga.
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.