id summary reporter owner description type status milestone component version severity resolution keywords cc 11139 boost::container::vector, std::allocator>::const_iterator allows changing its dereferenced elements matteo.settenvini@… Ion Gaztañaga "Consider the following attempt to make a `const_iterator` for a vector of smart pointers, be de-referentiable only to smart pointers to constant types: {{{ #!c++ #include #include class C { public: using a_type = int; using shared_ptr = std::shared_ptr; using shared_constptr = std::shared_ptr; // In my code, I am using a more complex allocator // in shared memory from boost::interprocess. using some_fixed_allocator = std::allocator; using vector = boost::container::vector; using cvector = boost::container::vector; C () { shared_ptr p = std::make_shared (1); _v.push_back (p); } cvector::const_iterator first_element () const { return _v.begin (); } private: vector _v; }; int main () { C c; C::cvector::const_iterator it = c.first_element (); **it = 2; // Expecting an error! // Note that we have an error using std::vector. } }}} This compiled cleanly with G++ 4.9 with `-std=c++11`, which really is hiding the problem as the const_iterator allows changing elements of a the `cvector` type. Using a std::vector at least results in the following compilation error: {{{ allocator-rebind.cc: In member function ‘std::vector, std::allocator >::const_iterator C::first_element() const’: allocator-rebind.cc:31:26: error: could not convert ‘((const C*)this)->C::_v.std::vector<_Tp, _Alloc>::begin, std::allocator >()’ from ‘std::vector, std::allocator >::const_iterator {aka __gnu_cxx::__normal_iterator*, std::vector, std::allocator > >}’ to ‘std::vector, std::allocator >::const_iterator {aka __gnu_cxx::__normal_iterator*, std::vector, std::allocator > >}’ return _v.begin (); }}} I suspect all the other containers in boost::container suffer from the same problem, e.g. they allow compilation of something wrong. Incidentally, it would be nice to have a way to rebind iterators for smart pointers, so that full encapsulation can be achieved also for `const` accessor methods." Bugs closed To Be Determined container Boost 1.57.0 Problem fixed felix.klar@…