auto_ptr not behaving as per header comment
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com 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); } However, if I comment out the std::auto_ptr<foo> ptr = get_bar(); line, it compiles. 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 _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com 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 */ 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]' 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?) smime.p7s
participants (1)
-
Steve Checkoway