home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!allegra!alice!ark
- From: ark@alice.att.com (Andrew Koenig)
- Newsgroups: comp.lang.c++
- Subject: Re: Destruction of temporaries
- Message-ID: <23599@alice.att.com>
- Date: 1 Sep 92 12:51:55 GMT
- Article-I.D.: alice.23599
- References: <MCGRANT.92Aug26232410@rascals.stanford.edu> <23563@alice.att.com> <rmartin.715004480@thor> <23583@alice.att.com> <rmartin.715101472@thor> <23590@alice.att.com> <rmartin.715268992@thor>
- Reply-To: ark@alice.UUCP ()
- Organization: AT&T Bell Laboratories, Murray Hill NJ
- Lines: 45
-
- In article <rmartin.715268992@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
-
- > These strategies should not supress the warnings. ANY time an address
- > or reference to a temporary is taken, whether is is via implicit
- > conversion, or as the argument of a member function, a warning should
- > be issued. No exceptions.
-
- > This will flag every instance where a long lived alias to a temporary
- > could be created.
-
- No, it will flag some instances. For example:
-
- struct A {
- A& foo();
- };
-
- A a();
-
- main()
- {
- A& b = a().foo();
- }
-
- Should this give a warning or not? It is impossible to tell without seeing the
- definition of A::foo. For instance, it might be:
-
- A& A::foo() {
- static A aa;
- return aa;
- }
-
- in which case there is no problem, or it might be
-
- A& A::foo() {
- return *this;
- }
-
- in which case there is. Without seeing it, the compiler can't tell.
-
- But looking at A::foo without seeing main, it's impossible to tell either.
- Returning *this from a member function is completely innocent unless the
- member happens to be called on a temporary object.
- --
- --Andrew Koenig
- ark@europa.att.com
-