home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12719 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  1.8 KB

  1. Path: sparky!uunet!olivea!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: destruction of temporaries
  5. Message-ID: <TMB.92Aug21142555@arolla.idiap.ch>
  6. Date: 21 Aug 92 18:25:55 GMT
  7. References: <BszApE.49v@world.std.com> <1992Aug17.073500.24115@ericsson.se>
  8.     <23466@alice.att.com> <3920@starlab.UUCP> <23487@alice.att.com>
  9.     <TMB.92Aug20142610@arolla.idiap.ch> <23507@alice.att.com>
  10. Sender: news@ai.mit.edu
  11. Reply-To: tmb@idiap.ch
  12. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  13.     Perceptive)
  14. Lines: 29
  15. In-reply-to: ark@alice.att.com's message of 20 Aug 92 21:16:28 GMT
  16.  
  17. In article <23507@alice.att.com> ark@alice.att.com (Andrew Koenig) writes:
  18.  
  19.    In article <TMB.92Aug20142610@arolla.idiap.ch> tmb@idiap.ch writes:
  20.  
  21.    > You can avoid unexpected behavior involving temporaries by programming
  22.    > defensively. In particular, this means: do _not_ return a reference or
  23.    > pointer to an explicit or implicit argument or its contents (*this,
  24.    > call-by-value, call-by-reference). Furthermore, do _not_ define cast
  25.    > operators to pointer types in your classes (instead, make them normal
  26.    > member functions that you have to call explicitly).
  27.  
  28.    I wish life were that simple.  The trouble comes with expressions like
  29.  
  30.        foo().bar().baz()
  31.  
  32.    where bar returns *this. If an implementation is allowed to delete
  33.    the result of foo() before calling baz, the roof can cave in even
  34.    if your defensive rules are followed.
  35.  
  36. Read my paragraph again. I explicitly stated you shouldn't return a
  37. reference to "*this".
  38.  
  39.    That is enough to argue, at least for me, that the current rule of
  40.    allowing temporaries to be destroyed as soon as they are fetched,
  41.    is too liberal.
  42.  
  43. All I can say is that I disagree.
  44.  
  45.                     Thomas.
  46.