Topic: lifetime of temporaries
Author: cline@sun.soe.clarkson.edu (Marshall Cline)
Date: 27 Jun 94 08:44:01 Raw View
============================================================
ANSI/ISO working paper recently tightened down the issues regarding
lifetime of temporaries. A temporary now lives until the outermost
expression (which is not a subexpression of any other expression).
My question is with regard to bound temporaries. If a reference is
bound to a temporary, will the temporary be guaranteed to live as long
as the reference lives?
--
Marshall Cline
--
Marshall P. Cline, Ph.D. / Paradigm Shift Inc / PO Box 5108 / Potsdam NY 13676
cline@parashift.com / 315-353-6100 / FAX: 315-353-6110
Author: thomson@cppfs.torolab.ibm.com (Brian Thomson)
Date: 27 Jun 1994 14:16:33 GMT Raw View
In article <CLINE.94Jun27084401@cheetah.clarkson.edu>,
Marshall Cline <cline@parashift.com> wrote:
>============================================================
>
>My question is with regard to bound temporaries. If a reference is
>bound to a temporary, will the temporary be guaranteed to live as long
>as the reference lives?
Before anyone answers "Yes!", consider how to handle
class A {
public:
const int &i;
A(int init) : i( init+0 ) {}
};
particularly when objects of class A may be static, automatic, or heap
allocated, and where other constructors of A may bind "i" to a
non-temporary.
IBM C/Set compilers currently deal with this by producing the following
warning:
"cline.C", line 5.25: 1540-475: (W) A local variable or compiler temporary
is being used to initialize reference member "i".
--
Brian Thomson THOMSON at TOROLAB
OS/2 C++ Development thomson@vnet.ibm.com
Author: jason@cygnus.com (Jason Merrill)
Date: Tue, 28 Jun 1994 04:06:00 GMT Raw View
>>>>> Marshall Cline <cline@sun.soe.clarkson.edu> writes:
> My question is with regard to bound temporaries. If a reference is
> bound to a temporary, will the temporary be guaranteed to live as long
> as the reference lives?
Yes.
Jason
Author: jason@cygnus.com (Jason Merrill)
Date: Tue, 28 Jun 1994 08:58:43 GMT Raw View
>>>>> Brian Thomson <thomson@cppfs.torolab.ibm.com> writes:
> In article <CLINE.94Jun27084401@cheetah.clarkson.edu>,
> Marshall Cline <cline@parashift.com> wrote:
>> ============================================================
>> My question is with regard to bound temporaries. If a reference is
>> bound to a temporary, will the temporary be guaranteed to live as long
>> as the reference lives?
> Before anyone answers "Yes!", consider how to handle
> class A {
> public:
> const int &i;
> A(int init) : i( init+0 ) {}
> };
> particularly when objects of class A may be static, automatic, or heap
> allocated, and where other constructors of A may bind "i" to a
> non-temporary.
Ah ha...looking at the WP again, I see that it only guarantees that the
temporary live as long as the scope in which it was created (the body of
A(int)), not as long as the reference itself. My mistake.
Jason