From -6344506630089513662
X-Google-Thread: f78e5,174aa7b34b06a51
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!newsfeed.vmunix.org!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: dave@boost-consulting.com (David Abrahams)
Newsgroups: comp.std.c++
Subject: Re: Is this really unspecified behavior?
Date: Fri, 16 Dec 2005 05:59:13 GMT
Lines: 69
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <uzmn23zsm.fsf@boost-consulting.com>
References: <1132759176.368850.264850@g43g2000cwa.googlegroups.com>
	<H1phf.161529$zb5.99785@bgtnsc04-news.ops.worldnet.att.net>
	<1132933832.802917.153350@g14g2000cwa.googlegroups.com>
	<1133551647.532929.325730@z14g2000cwz.googlegroups.com>
	<1133583412.951239.208510@g49g2000cwa.googlegroups.com>
	<E1EjGBD-0005T8-00@chx400.switch.ch>
	<1133910546.716987.80030@g14g2000cwa.googlegroups.com>
	<E1EjzL6-0006ic-00@chx400.switch.ch>
	<0l5ep1ppfhdj5p1pcu7e4na4ub0vjajlq3@4ax.com> <200512131507.jBDF72uC0
	<IrIz47.GnJ@beaver.cs.washington.edu>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.demon.co.uk 1134712766 14374 158.152.254.254 (16 Dec 2005 05:59:26 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 16 Dec 2005 05:59:26 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (windows-nt)
X-DMCA-Complaints-To: abuse@rcn.net
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Cancel-Lock: sha1:FD8f0yoUl2H/uuVg7XvnxCtavOo=
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id jBG5xDu0013664;
	Fri, 16 Dec 2005 16:59:13 +1100 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-NNTP-Posting-Date: Thu, 15 Dec 2005 13:50:00 -0600
X-Delivered-To: std-c++@ucar.edu
X-TN-Interface: 209.99.127.21
X-Postfilter: 1.3.32
X-Authentication-Warning: serv4.gc.dca.giganews.com: news set sender to poster@giganews.com using -f
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:2782

"Andrei Alexandrescu (See Website For Email)" <SeeWebsiteForEmail@moderncppdesign.com> writes:

> Bob Bell wrote:
>> It strikes me that the phrase "code which tries to be safe really can
>> be safe" applies to the situation today as well. Here's some code that
>> "tries to be safe" today:
>>    std::auto_ptr<int> p1(new int(0));
>>    std::auto_ptr<int> p2(new int(0));
>>    function_taking_two_auto_ptrs(p1, p2);
>
> Hmmm... I think Hyman had a different definition of "code that tries to 
> be safe". The meaning would be "code that doesn't manipulate at any 
> moment bald pointers". You see, the thing is that the code
>
> function_taking_two_auto_ptrs(auto_ptr<int>(new int), auto_ptr<int>(new 
> int))
>
> does not expose at any moment any bald pointer, 

Of course 

     new int

exposes a bald pointer.  That's *precisely* the root cause of the
problem.  That should be encapsulated in

     new_<auto_ptr<int> >()

It's even less typing.

> yet it can fail for very ocult reasons. 
                           ^^^^^
cute.

> Of course if we extend the definition of "code that tries to be
> safe" appropriately, we can do a lot of things safely :o). It will
> just take a lot of effort and rules to memorize.

You can't extend the definition before defining it :)

> So bottom line is that the case of functions taking several
> auto_ptrs is peculiar -- it's unsafe in spite of the user not doing
> anything unsafe at any moment.

So you seem to be starting with the axiom that

   foo( auto_ptr<T>( new T ), auto_ptr<T>( new T ) )

isn't "unsafe at any moment."  But of course it is completely unsafe
or we wouldn't be having this discussion.  And you find that to
conflict with your axiom.  So that line of reasoning seems circular to
me.

All that said, I can see an argument for your position.  I think you'd
like exception-safety to be "context free," so that if expression1 and
expression2 are each exception-safe, then some expression3 composed of
expression1 and expression2 is also exception-safe.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



