Boost logo

Boost :

From: md656 (md656_at_[hidden])
Date: 2001-03-27 12:38:40


Hi...

This may seem off-topic, but it is important since Boost is build on STL. I
am using Dinkumware STL that comes with MSVC6.

Look at the following code

#include <iostream>
#include <memory>
using namespace std;

template <class T>
ostream& operator << (ostream& strm, const auto_ptr<T>& p)
{
 if (p.get() == NULL)
 {
  strm << "NULL";
 }
 else {
  strm << *p;
 }
 return strm;
}

int main()
{
 auto_ptr<int> p(new int(42));
 auto_ptr<int> q;

 cout << "after initialization:" << endl;
 cout << " p: " << p << endl;
 cout << " q: " << q << endl;

 q=p;
 cout << "after assigning auto pointers:" << endl;
 cout << " p: " << p << endl;
 cout << " q: " << q << endl;

 *q+=13;
 p=q;
 cout << "after change and reassignment:" << endl;
 cout << " p: " << p << endl;
 cout << " q: " << q << endl;
}

The output from MSVC is:

after initialization:
p: 42
q: NULL
after assigning auto pointers:
p: 42
q: 42
after change and reassignment:
p: 55
q: 55

While the real answer must be
after initialization:
p: 42
q: NULL
after assigning auto pointers:
p: NULL
q: 42
after change and reassignment:
p: 55
q: NULL

Is this a bug?

Mohammed


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk