This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Help: auto_ptr conversion confusion
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: Kristian Spangsege <kristian dot spangsege at framfab dot dk>
- Cc: libstdc++ at gcc dot gnu dot org, jackw_reeves at hotmail dot com
- Date: Fri, 11 Oct 2002 12:40:06 -0500
- Subject: Re: Help: auto_ptr conversion confusion
- Organization: Red Hat / Chicago
- References: <51DDD38845C4D31182D900508BE185B7F07730@dkcopmail01.framfab.dk>
> I am unsure if it is an error in the implemetation of auto_ptr or if
> it is an error in the G++ frontend, or just an incorrect library
> documentation.
>
> The aparent problem is that the following selfcontained program
> does not compile with GCC3.2:
>
> 1 #include <memory>
> 2 using namespace std;
> 3
> 4 struct A {};
> 5 struct B: A {};
> 6
> 7 auto_ptr<B> f()
> 8 {
> 9 auto_ptr<B> b;
> 10 return b;
> 11 }
> 12
> 13 int main()
> 14 {
> 15 auto_ptr<A> a = f();
> 16 return 0;
> 17 }
I think this usage is in error.
> But in your source level documentation you state that the
> alternative construct using = should work:
> http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.2/classstd_1_
> 1auto__ptr.html#z15_3
>
>
> Could someone explain to me exactly what the semantical difference (if
> any) is between these two versions of line 15:
>
> 15 auto_ptr<A> a = f();
> 15 auto_ptr<A> a(f());
>
> Does gcc3.2 handle these alternative constructs the way it is intended
> ib the C++ standard?
I think this documentation should be corrected.
I'm uncertain about this, and have cc'd Jack Reeves, who seems to have
done the latest work on std::auto_ptr. Perhaps he'll be able to explain
in more detail.
-benjamin