[Boost-bugs] [Boost C++ Libraries] #5191: intrusive unordered_set: const version of iterator_to() won't compile

Subject: [Boost-bugs] [Boost C++ Libraries] #5191: intrusive unordered_set: const version of iterator_to() won't compile
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-02-14 20:54:26


#5191: intrusive unordered_set: const version of iterator_to() won't compile
-----------------------------------+----------------------------------------
 Reporter: paul.d.rose@… | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: intrusive
  Version: Boost 1.45.0 | Severity: Problem
 Keywords: |
-----------------------------------+----------------------------------------
 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];
    base_set.iterator_to(cr);
 }}}
 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);
 }}}
 to:
 {{{
   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.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5191>
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:05 UTC