home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mole-end!mat
- From: mat@mole-end.matawan.nj.us
- Subject: Re: destruction of temporaries
- Message-ID: <1992Aug31.172743.8788@mole-end.matawan.nj.us>
- Summary: Has anyone considered
- Organization: :
- References: <23487@alice.att.com> <MATT.92Aug19170229@physics16.berkeley.edu> <23585@alice.att.com>
- Date: Mon, 31 Aug 1992 17:27:43 GMT
- Lines: 39
-
- In article <23585@alice.att.com>, ark@alice.att.com (Andrew Koenig) writes:
- > In article <1992Aug28.221841.149034@Cookie.secapl.com> frank@Cookie.secapl.com (Frank Adams) writes:
- >
- > > I don't claim to have a complete solution to the problem. However, for the
- > > specific case c ? a+b : a where a+b creates a temporary, I would be
- > > tempted (as a compiler writer) to always return a temporary: ...
-
- > I'm afraid it doesn't solve the problem. For example, suppose `a' is of type
- > const char*, `b' is of type String, and String has one of those problematic
- > conversions to const char*. Now, let's modify your example a tiny bit and
- > look at c?(const char*)(a+b):a.
-
- > This expression always returns a value of type const char*, but that's not
- > where the problem likes: the problem is in the temporary of type String
- > yielded by the subexpression a+b. The value of (const char*)(a+b) is valid
- > only so long as that temporary stays around, so any games you play with
- > the const char* values themselves won't affect that.
-
- Andy, have we considered the following?
-
- A temporary that is created has a lifetime equivalent to
- the thing to which it is bound by initialization. (This
- includes the initialization of function parameters-by-reference
- and the intialization of a this pointer.)
-
- A temporary that is _converted_ (in the C++ sense of the
- word) is considered to be bound to whatever the converted
- value initializes.
-
- Return values of other sort (from member functions) do not
- affect the lifetime.
-
- I'm sure we have ... but it seems to me this answers most of the
- problems.
- --
- (This man's opinions are his own.)
- From mole-end Mark Terribile
-
- mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
-