🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2406

Re: auto_ptr<T> as function return type

#2406
From: Stein Somers
Date: Thu, 02 Nov 1995 23:25
41 lines
1997 bytes
Fergus Henderson (fjh@munta.cs.mu.OZ.AU) wrote:
: Yep.  With the current spec., you need to write

: 	auto_ptr<double> p(f().release());

: and

: 	p.reset(f().release());

: instead.

This has been mentioned earlier, of course.  So I'd like to repost
this recent uncountered reply:

Eric Biederman (ebiederm@cse.unl.edu) wrote:
: There is a case where it doesn't work.
: 
: The problem is that you are passing it as a standard pointer type.
: What happens if you were to run out of stack after the call to release
: and before the call to the constructor, or reset.  And an exception is
: thrown.
: 
: If your program actualy catches that exception then a memory leak has
: occured. ( A rare case I will admit).
: 
: There are probably more realistic examples is less mundane code.

Maybe when an object containing many auto_ptr's is returned, in which
case the auto_ptr's must be moved jointly?

: It must be in an object at all times TO BE SAFE!

Any remarks, please?


Stein Somers (somers@intec.rug.ac.be)
INTEC - IMEC/University of Gent, Belgium
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <47b1um$fvs@infoserv.rug.ac.be>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <47616o$lvr@bcarh8ab.bnr.ca> <VANDEVOD.95Oct31222003@juicer.cs.rpi.edu> <9530600.21749@mulga.cs.mu.OZ.AU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 02 Nov 95 23:25:51 GMT
Approved: fjh@cs.mu.oz.au
From: uunet!PROBLEM_WITH_INEWS_GATEWAY_FILE!somers@ncar.UCAR.EDU (Stein Somers)
Newsgroups: comp.std.c++
Subject: Re: auto_ptr<T> as function return type
X-Original-Date: 2 Nov 1995 18:16:53 GMT
Organization: University of Ghent, Belgium
Message-ID: <47b1um$fvs@infoserv.rug.ac.be>
References: <47616o$lvr@bcarh8ab.bnr.ca> <VANDEVOD.95Oct31222003@juicer.cs.rpi.edu> <9530600.21749@mulga.cs.mu.OZ.AU>
X-Newsreader: TIN [version 1.2 PL2]
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMJlTyeEDnX0m9pzZAQEHmgF7BApFs65HTcTAUahQu12XpNYdCw8DNah0
 a93n6a7OjF9f4QoYtt5vgkmmjfe7X+/P
 =4tOj