From -4014339613273917725
X-Google-Thread: f78e5,174aa7b34b06a51
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news3.google.com!news.glorb.com!molokai.public-internet.co.uk!newspeer.public-internet.co.uk!peer.news.zetnet.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: nagle@animats.com (John Nagle)
Newsgroups: comp.std.c++
Subject: Re: Is this really unspecified behavior?
Date: Sun, 18 Dec 2005 05:40:16 GMT
Organization: SBC http://yahoo.sbc.com
Lines: 50
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <Tt6pf.30915$BZ5.5394@newssvr13.news.prodigy.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>	<IrIz47.GnJ"@beaver.cs.washington.edu>	<uzmn23zsm.fsf@boost-consulting.com>	<200512161412.jBGECcuC061966@horus.isnic.is>	<uwti43m41.fsf@boost-consulting.com>	<howard.hinnant-DB53B6.14161817122005@syrcnyrdrs-02-ge0.nyroc.rr.com> <87bqzfp5t2.fsf@boost-consulting.com>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.demon.co.uk 1134884423 3768 158.152.254.254 (18 Dec 2005 05:40:23 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sun, 18 Dec 2005 05:40:23 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.11) Gecko/20050728
X-Accept-Language: en-us, en, ja
X-Virus-Scanned: amavisd-new at cs.mu.OZ.AU
X-UserInfo1: O@YORZSDTBSUCFH[OZK@_TDAYZOZ@GXOXZ^D]\YIJYWZUYICD^RAQBKZQTZTX\_I[^G_KGFNON[ZOE_AZNVO^\XGGNTCIRPIJH[@RQKBXLRZ@CD^HKANYVW@RLGEZEJN@\_WZJBNZYYKVIOR]T]MNMG_Z[YVWSCH_Q[GPC_A@CARQVXDSDA^M]@DRVUM@RBM
X-Path: comp-std-cpp-robomod!not-for-mail
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id jBI5eGgP024388;
	Sun, 18 Dec 2005 16:40:16 +1100 (EST)
X-NNTP-Posting-Date: Sun, 18 Dec 2005 00:30:27 EST
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:2815

David Abrahams wrote:

> howard.hinnant@gmail.com (Howard Hinnant) writes:
> 
> 
>>In article <uwti43m41.fsf@boost-consulting.com>,
>> dave@boost-consulting.com (David Abrahams) wrote:
>>
>>
>>>>The problem with the current language definition
>>>>is that the compiler has too much freedom to reorder
>>>>expressions, and that leads to unsafe code. 

What's really going on here is that the sequence
of events from the "new" to the assignment of the
result of auto_ptr is an atomic operation.  Either
it needs to run to completion or it needs to have
no effect.  The way you protect an atomic
operation is to enclose it in a try block.  You
can't do that inside an expression.

Actually, the problem is that the compiler doesn't
know enough about side effects.  Properly,
functions without side effects are reorderable
(and even subject to folding of multiple calls),
while functions with side effects should not
be reordered.

The most elegant solution is that the compiler
should know, for inlines and well-known
library functions, which functions have
no side effects.  (Throwing an exception
is a side effect here.)  Reordering of calls
in the presence of potential side effects
should be prohibited.

If a function is too complex to resolve the
side effect issue or not inline, it's best to
assume that it has side effects.  If it's a
big function, the small speed benefits of reordering
won't matter anyway.

			John Nagle

---
[ 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                       ]



