auto_ptr not behaving as per header comment
auto_ptr not behaving as per header comment
- Subject: auto_ptr not behaving as per header comment
- From: Steve Checkoway <email@hidden>
- Date: Tue, 9 Aug 2005 18:56:24 -0700
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:
This email sent to email@hidden