Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Auto_ptr<> woes...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 9778 of 9909
Post > Topic >>

Auto_ptr<> woes.

by Vaclav Haisman <v.haisman@[EMAIL PROTECTED] > Jul 10, 2008 at 02:06 PM

Hi,
I have the following test case which is boiled down from real code. The
problem is that Foo * foo (); auto_ptr<Foo> ap; ap = foo (); does not do
what
I thought it should have done. With GCC it does not compile; with MSVC8 it
does compile but breaks. I have stepped through the MSVC8 compiled code
and
it goes through auto_ptr_ref(void *_Right) to auto_ptr<_Ty>&
operator=(auto_ptr_ref<_Ty> _Right).

My questions are: Is MSVC8 right? Should it even compile? Is there
something
in the standard that makes the ap = foo () assignment having undefined
behaviour?


----------------------8<-----------------------
#include <memory>
#include <iostream>

struct Data
{ };


Data *
foo ()
{
     return new Data;
}


int
main ()
{
     {
         std::auto_ptr<Data> ap;
         // This compiles but breaks with MSCV8.
         // and does not compile with GCC.
         ap = foo ();
         std::cout << "ap: " << ap.get () << std::endl;
     }

     {
         // This works as intended.
         std::auto_ptr<Data> ap (foo ());
         std::cout << "ap: " << ap.get () << std::endl;
     }

     std::cin.get ();
}

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 6 Posts in Topic:
Auto_ptr<> woes.
Vaclav Haisman <v.hais  2008-07-10 14:06:56 
Re: Auto_ptr<> woes.
Alberto Ganesh Barbati &l  2008-07-10 20:28:06 
Re: Auto_ptr<> woes.
Pavel Minaev <int19h@[  2008-07-11 14:19:17 
Re: Auto_ptr<> woes.
Diego Martins <jose.di  2008-07-11 14:18:55 
Re: Auto_ptr<> woes.
Diego Martins <jose.di  2008-07-11 14:19:07 
Re: Auto_ptr<> woes.
yanoscuni <yanoscuni@[  2008-07-11 14:14:04 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 4:43:26 CDT 2008.