home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13134 < prev    next >
Encoding:
Text File  |  1992-08-31  |  2.1 KB  |  51 lines

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