home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!uunet.ca!frumious!pat
- From: pat@frumious.uucp (Patrick Smith)
- Subject: Re: Destruction of temporaries
- Message-ID: <1992Aug29.184025.328@frumious.uucp>
- Date: Sat, 29 Aug 1992 18:40:25 GMT
- Reply-To: uunet.ca!frumious!pat
- References: <rmartin.715004480@thor> <23583@alice.att.com> <rmartin.715101472@thor>
- Organization: None
- Lines: 28
-
- rmartin@thor.Rational.COM (Bob Martin) writes:
- |String& f(String& x) {return x;}
- |
- |String a,b;
- |char* c = f(a+b);
- |
- |The above is more of a problem, becuase in order to provide the
- |necessary warning, the compiler must warn whenever a reference to a
- |temporary is taken. This would generate warnings even when there was
- |no danger. But that's what warnings are all about.
-
- My feeling is that if a compiler did this, the meaningful warnings
- would be buried in a landslide of warnings for completely safe cases.
- For example,
-
- String operator+(const String& s1, const String& s2);
-
- String a, b, c, d;
- d = a + b + c;
-
- In evaluating the second sum, the reference s1 is bound to the
- temporary representing a+b. So the compiler would issue a warning,
- according to your rule.
-
- --
- Patrick Smith
- uunet.ca!frumious!pat
- pat%frumious.uucp@uunet.ca
-