Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

auto_ptr not behaving as per header comment



I was taking a look at /usr/include/gcc/darwin/4.0/c++/memory and I noticed this comment:
/**
* @brief Automatic conversions
*
* These operations convert an %auto_ptr into and from an auto_ptr_ref
* automatically as needed. This allows constructs such as
* @code
* auto_ptr<Derived> func_returning_auto_ptr(.....);
* ...
* auto_ptr<Base> ptr = func_returning_auto_ptr(.....);
* @endcode
*/


I decided to give it a try:
$ cat auto_ptr_test.cpp
#include <memory>

struct foo { };
struct bar : public foo { };

std::auto_ptr<bar> get_bar() { return std::auto_ptr<bar>(new bar); }

int main()
{
std::auto_ptr<foo> ptr = get_bar();
std::auto_ptr<foo> ptr2(get_bar());
return 0;
}
$ g++ -Wall auto_ptr_test.cpp
auto_ptr_test.cpp: In function 'int main()':
auto_ptr_test.cpp:10: error: no matching function for call to 'std::auto_ptr<foo>::auto_ptr(std::auto_ptr<foo>)'
/usr/include/gcc/darwin/4.0/c++/memory:349: note: candidates are: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr_ref<_Tp>) [with _Tp = foo]
/usr/include/gcc/darwin/4.0/c++/memory:212: note: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp1>&) [with _Tp1 = foo, _Tp = foo]
/usr/include/gcc/darwin/4.0/c++/memory:199: note: std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>&) [with _Tp = foo]
auto_ptr_test.cpp:10: error: initializing temporary from result of 'std::auto_ptr<_Tp>::operator std::auto_ptr<_Tp1>() [with _Tp1 = foo, _Tp = bar]'


However, if I comment out the
std::auto_ptr<foo> ptr = get_bar();
line, it compiles.

Am I doing something incorrectly here or is there a bug in g++ or is the header file simply wrong? (Or a combination of the above?)

It looks like the third candidate:
std::auto_ptr<_Tp>::auto_ptr(std::auto_ptr<_Tp>&) [with _Tp = foo]
should match
std::auto_ptr<foo>::auto_ptr(std::auto_ptr<foo>)
but for some reason, it  isn't.

- Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.