From 2792752291592773988
X-Google-Thread: f78e5,ff39f62da1e60460
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news3.google.com!news.glorb.com!newsfeed.stueberl.de!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: jpotter@lhup.edu (John Potter)
Newsgroups: comp.std.c++
Subject: Re: Temporary object's lifetime and Full-expression
Date: Sat, 23 Apr 2005 01:21:22 GMT
Organization: EarthLink Inc. -- http://www.EarthLink.net
Lines: 124
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <n%gae.11176$sp3.3616@newsread3.news.atl.earthlink.net>
References: <d47or0$n1a$1@news.kreonet.re.kr>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: news.demon.co.uk 1114219288 23022 158.152.254.254 (23 Apr 2005 01:21:28 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sat, 23 Apr 2005 01:21:28 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
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 j3N1LMlC007272;
	Sat, 23 Apr 2005 11:21:22 +1000 (EST)
X-NNTP-Posting-Date: Fri, 22 Apr 2005 17:52:35 PDT
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-Newsreader: Forte Free Agent 1.93/32.576 English (American)
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:4575

On Fri, 22 Apr 2005 19:44:48 GMT, stkim@yujinrobot.com ("Kim, Seungtai")
wrote:

> "What about this case? Is it legel and dose it produce well-defined behavior?"

>     struct A {
>         A& me() { return *this; }
>     };

>     void foo(const A* a);
>     ...
>     foo( &A().me() );

> I said it's not. It will make the undefined behavior. The reason is that
> the temporary object will be destroyed at the point of immediately after
> calling function foo. Therefore foo will get the dangling pointer. It's
> illegal use of invalid pointer.

No.

> But the others assist the opposite opinion that the temporary object
> will not be destroyed until the completion of the full expression
> calling foo.

Yes.

The major problem in all that follows is quoting out of context.

> My opinion comes from the definition of the temporary object's lifetime
> and the full-expression. 12.2/p3 states the general rule for lifetime of
> the temporary object.

>     12.2/p3
>     Temporary objects are destroyed as the last step in evaluating
>     the full-expression (1.9) that (lexically) contains the point
>     where they were created.

Fine.

> And 1.9/p12 states the definition of the full-expression.
> 
>     1.9/p12
>     A full-expression is an expression that is not a subexpression
>     of another expression.

Fine.

> And 1.9/p13 describes the function call is full expression, also.

>     1.9/p13
>     ... the function call is a full-expression.

No, you are out of context.  The context is initialization which
contains no syntactic expression yet is treated as a full-expression
consisting of a function call.

struct S { S (int); };
void f () {
   S s1(1);  // No expression, but treated as function call
   S s2 = 2; // Same
   }

The text does not say that all function calls are full-expressions.  It
says that these two cases are full-expression function calls.

> In this point, there can be two different but ciritical interpretations
> whether the function call in an expression is a sub-expression
> or not it's an independent full expression.

Not if you read everything and not just part.

> - The function call is sub-expression. It's explicitly included in
> the other expression. So, the temporary object should not be destroyed
> until after evaluating full expression that contains the function call.
> Therefore OP's above code is legal and produce well-defined behavior.

Yes.

> - The function call is full expression that it is independent
> from the expression containing the function call. For that reason, the
> temporary object shold be destroyed immediately after calling function.
> Hance, above code will make UB.

No.

> I have the more questions if we assume that the function call is a
> sub-expression of the other expression.

> 1. Why dose the bellow sentance exist?
> 
>     12.4/p5

This is 12.2/5.

>     ... A temporary bound to a reference parameter in a function
>     call(5.2.2) persists until the completion of the full
>     expression containing the call. ...

You are again missing the major point.  A temporary bound to a reference
normally has the its lifetime extended to that of the reference.  This
is an exception to that rule because the temporary outlives the
reference which terminates upon return.

> If function call is a sub-expression, it's not required. Always
> the temporary object survives until the completion of the full
> expression containing the function call. Why it needed?

To emphasize that it outlives the reference which is the subject of
this paragraph.

> 2. Why dose the 1.9/p13 emphasize "function call is a full expression."
> twice.

See above.  It is talking about two special cases where a non-expression
syntax is treated as a full-expression.

John

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



