|
Boost : |
From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-10-27 21:58:42
From: <jeremy_at_[hidden]>
> I'm using MSVC++ v6sp5 and I have noticed that the following compiles
> without error:
Amazing. I wonder how it mangaged to turn 0 into something
assignable to shared_ptr?
> --- file: test.cpp ---
> #include <boost/smart_ptr.hpp>
> #include <stdio.h>
>
> void main() {
> boost::shared_ptr<int> p( new int(5) );
> p= 0;
> printf( "%x\n", p.get() );
> }
> ----------------------
>
> What's worse is that it prints out a non-zero number for p.get().
> Obviously p.reset( 0 ) has the desired effect, which makes sense
> since p's constructor is marked explicit. Assignments of the form "p=
> 0" appear to generate no errors, warnings or object code for all
> cases where p's operator= is templated.
>
> Is this a confirmed bug in VC++ or have I missed something dreadfully
> obvious? Is there a workaround for shared_ptr?
I don't know about confirmed, but it sure looks like a bug.
I guess the workaround is just "don't do that". Or perhaps
an operator=(void*) could be added to shared_ptr with a
compile-time assert saying "don't do that". Or just give
up and admit that Microsoft doesn't yet ship a C++ compiler.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk