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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!uunet.ca!frumious!pat
  3. From: pat@frumious.uucp (Patrick Smith)
  4. Subject: Re: Destruction of temporaries
  5. Message-ID: <1992Aug29.184025.328@frumious.uucp>
  6. Date: Sat, 29 Aug 1992 18:40:25 GMT
  7. Reply-To: uunet.ca!frumious!pat
  8. References: <rmartin.715004480@thor> <23583@alice.att.com> <rmartin.715101472@thor>
  9. Organization: None
  10. Lines: 28
  11.  
  12. rmartin@thor.Rational.COM (Bob Martin) writes:
  13. |String& f(String& x) {return x;}
  14. |
  15. |String a,b;
  16. |char* c = f(a+b);
  17. |
  18. |The above is more of a problem, becuase in order to provide the
  19. |necessary warning, the compiler must warn whenever a reference to a
  20. |temporary is taken.  This would generate warnings even when there was
  21. |no danger.  But that's what warnings are all about.
  22.  
  23. My feeling is that if a compiler did this, the meaningful warnings
  24. would be buried in a landslide of warnings for completely safe cases.
  25. For example,
  26.  
  27.    String operator+(const String& s1, const String& s2);
  28.  
  29.    String a, b, c, d;
  30.    d = a + b + c;
  31.  
  32. In evaluating the second sum, the reference s1 is bound to the
  33. temporary representing a+b.  So the compiler would issue a warning,
  34. according to your rule.
  35.  
  36. -- 
  37. Patrick Smith
  38. uunet.ca!frumious!pat
  39. pat%frumious.uucp@uunet.ca
  40.