Boost logo

Boost Users :

From: JD (jean.daniel.michaud_at_[hidden])
Date: 2007-03-31 08:27:46


Hello,

   Anyone has an idea why this code crashes:

// snippet on
#include <list>
#include <string>
#include <iostream>
#include <boost/shared_ptr.hpp>

struct null_deleter { void operator()(void const *) const {} };

int main()
{
   std::list<boost::shared_ptr<std::ostream> > l;

   boost::shared_ptr<std::ostream> p(&std::cout, null_deleter());
   *p << "on the shared pointer" << std::endl;
   l.push_back(p);

   std::list<boost::shared_ptr<std::ostream> >::iterator it =
l.begin();
   std::cout << "before loop" << std::endl;
   while (it++ != l.end())
   {
     boost::shared_ptr<std::ostream> p2 = *it;
     *p2 << "test" << std::endl; // crash here
   }

   return 0;
}

// snippet off

// output on
on the shared pointer
before loop
segmentation fault
// output off

It crashes on:
  std::ostream::sentry::sentry () from /usr/lib/libstdc++.so.6

Thanks.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net