Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!cs.utexas.edu!mailrus!cornell!uw-beaver!apollo!mrst!sdti!turner
From: turner@sdti.com (Prescott K. Turner)
Newsgroups: comp.lang.c++
Subject: Lifetimes for Temporaries (was Re: Strings)
Message-ID: <1989Oct25.181309.14515@sdti.com>
Date: 25 Oct 89 18:13:00 GMT
References:
Reply-To: turner@sdti.SDTI.COM (Prescott K. Turner, Jr.)
Distribution: comp
Organization: Software Development Technologies, Inc.
Lines: 29
In article dl@oswego.edu (Doug Lea) writes:
> ...
> 2) Change the C++ rules about lifetimes for temporaries, so that they,
> like `normal' variables have lifetimes to the end of the enclosing
> scope. This solution has merit on other grounds as well, but also
> creates some of its own difficulties. Actually, this may be going too
> far. The lifetime rules for temporaries say that if a *reference* to
> a temp (or any part thereof?) is taken (or any ref-returning member
> function is called?), then its lifetime *is* to the end of the enclosing
> scope. The char* conversion *behaves* like a reference, but is not
> one. I once proposed that C++ allow the idiom of a char[]& to mean a
> reference to a character array. Support of this would solve this (and
> other) problems, since one could create a
> char[]& String::chars() { return s /* or whatever */ ; },
> call it inside the ostream << int via `return put(dec(i).chars())',
> and everything would work just right. But no one has ever told me
> that they particularly like this idea.
Re-reading the cfront 2.0 reference manual, I doubt the passage on the
lifetime of temporaries was written with ref-returning functions in mind.
The above code returns an expression that requires a temporary from a
ref-returning function. I never thought that was supported by C++.
Cfront 1.2 certainly didn't implement it.
--
Prescott K. Turner, Jr.
Software Development Technologies, Inc.
P.O. Box 366, Sudbury, MA 01776 USA (508) 443-5779
UUCP: ...{harvard,mit-eddie}!sdti!turner Internet: turner@sdti.sdti.com