From -7273212585619446453
X-Google-Thread: f78e5,ff39f62da1e60460,start
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news4.google.com!news2.google.com!proxad.net!news.cs.univ-paris8.fr!newsfeed.vmunix.org!feed.news.tiscali.de!newsfeed.icl.net!newsfeed.fjserv.net!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: stkim@yujinrobot.com ("Kim, Seungtai")
Newsgroups: comp.std.c++
Subject: Temporary object's lifetime and Full-expression
Date: Fri, 22 Apr 2005 19:44:48 GMT
Organization: Korea Research Environment Open Network
Lines: 108
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <d47or0$n1a$1@news.kreonet.re.kr>
NNTP-Posting-Host: news.news.demon.net
X-Trace: news.demon.co.uk 1114199096 17121 158.152.254.254 (22 Apr 2005 19:44:56 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 22 Apr 2005 19:44:56 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
X-Priority: 3
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
X-MSMail-Priority: Normal
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id j3MJimlL004316;
	Sat, 23 Apr 2005 05:44:48 +1000 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-NNTP-Posting-Date: Thu, 21 Apr 2005 08:38:56 +0000 (UTC)
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: Microsoft Outlook Express 6.00.2600.0000
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:4565

There were some discussion about parameter passing of the temporary object
at the han.comp.lang.c++. The original question was simple why bellow code
dose not work.

 foo( &A() );

Yes. Clear. It's illegal use of operator & that requires the lvalue which
the tempporary dose not return. And there another question was followed.
"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.

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

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.

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.

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

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

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.

- 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.

- 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.

Which opinion is correct?

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
    ... 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. ...

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?
Am I something wrong and mis-interpretation?

2. Why dose the 1.9/p13 emphasize "function call is a full expression."
twice. If we think about that there are return of the function,
it's clear that the function call alone could not be the full-expression, always.
For example, in a "a = f( x ) ;", f( x ) is just a sub-expression,
not a full-expression. Another case, even f returns void and in
expression of "f( x );", the final expression is "void", not a function
call. For that reason, a function call itself can not be the full-expression.
And the explanation should be just a "expression" not a "full expression".
Is it overlooking?

3. Last one. Is there full expression in the C++ program if the function
call is just a sub-expression? I think there isn't. If we define the
function call makes the relation of the sub-expression, all the reacheable
functions comes from the main and creation realated functions for the
static obejcts. And they are called by execution environment. So, there is
no full-expression. Is it true?

Thanks in advice.

--
S Kim <stkim@yujinrobot.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                       ]



