[Boost-bugs] [Boost C++ Libraries] #2862: slist::swap is broken when cache_last< true > is used

Subject: [Boost-bugs] [Boost C++ Libraries] #2862: slist::swap is broken when cache_last< true > is used
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-03-17 06:51:23


#2862: slist::swap is broken when cache_last< true > is used
--------------------------+-------------------------------------------------
 Reporter: andysem | Owner: igaztanaga
     Type: Bugs | Status: new
Milestone: Boost 1.39.0 | Component: intrusive
  Version: Boost 1.38.0 | Severity: Showstopper
 Keywords: slist swap |
--------------------------+-------------------------------------------------
 Swapping two slists with the cache_last option yields an invalid slist.
 The following code snippet demonstrates the problem:

 {{{
 #include <iostream>
 #include <boost/checked_delete.hpp>
 #include <boost/intrusive/options.hpp>
 #include <boost/intrusive/slist.hpp>
 #include <boost/intrusive/slist_hook.hpp>

 namespace bi = boost::intrusive;

 typedef bi::slist_base_hook<
     bi::link_mode< bi::safe_link >
> BaseHook_t;

 struct MyData :
     public BaseHook_t
 {
     int m_Data;

     explicit MyData(int d) : m_Data(d) {}
 };


 int main(int, char*[])
 {
     typedef bi::slist<
         MyData,
         bi::base_hook< BaseHook_t >,
         bi::constant_time_size< true >,
         bi::cache_last< true >
> List_t;

     List_t l1;

     MyData* p = 0;
     p = new MyData(1); l1.push_back(*p);
     p = new MyData(2); l1.push_back(*p);
     p = new MyData(3); l1.push_back(*p);
     p = new MyData(4); l1.push_back(*p);

     std::cout << "l1.front() = " << &l1.front() << std::endl;

     List_t l2;

     l2.swap(l1);

     std::cout << "l2.front() = " << &l2.front() << std::endl; // should be
 the same as l1.front() above

     l2.clear_and_dispose(boost::checked_deleter< MyData >()); // this line
 crashes

     return 0;
 }
 }}}

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