auto_ptr bug

Marc A. Lepage mlepage@molecularmining.com
Mon Apr 10 11:35:00 GMT 2000


bgarcia@laurelnetworks.com wrote:
> 
> From libstc++ 2.90.8, bits/std_memory.h:
> 
> -----------------------------------------------------------------------------
> template <class _Tp> class auto_ptr {
> private:
>   _Tp* _M_ptr;
> 
> public:
> ...
>   auto_ptr(auto_ptr& __a) __STL_NOTHROW : _M_ptr(__a.release()) {}
> 
> -----------------------------------------------------------------------------
> 
> Shouldn't that constructor take a "const auto_ptr&" ?
> (therefore, release() should be const, and _M_ptr will probably need to
> be made mutable).

No. Copying an auto_ptr changes the original (it has to release
ownership).

> Among other things, the current interface means that you can't currently
> insert an entry into an stl map full of auto_ptr's (try it).

You cannot use auto_ptrs in standard containers. It is expressly
forbidden and designed to not work.

-- 
Marc A. Lepage
Software Developer
Molecular Mining Corporation
http://www.molecularmining.com/


More information about the Libstdc++ mailing list