Help: auto_ptr conversion confusion
Benjamin Kosnik
bkoz@redhat.com
Fri Oct 11 10:40:00 GMT 2002
> 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
More information about the Libstdc++
mailing list