home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!UB.com!igor!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: Destruction of temporaries
- Message-ID: <rmartin.715444704@thor>
- Date: 2 Sep 92 14:38:24 GMT
- 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> <23599@alice.att.com>
- Sender: news@Rational.COM
- Lines: 50
-
- ark@alice.att.com (Andrew Koenig) writes:
-
- |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 should, because the temporary created by 'a()' must be converted to
- a pointer in order to be used in the method call as 'this'. And, of
- course, this means that every time you invoke a method on a temporary,
- you will get a warning.
-
- Issuing warnings every time a method is invoked on a temporary is very
- ugly. #pragmas for selectively supressing such warnings are a
- solution, but not a very satisfying one. Still, it is when a pointer
- or reference to a temporary is taken, that the risk of a long lived
- alias is created; and a warning about that risk seems appropriate.
-
- In the absence of GC, or some other foolproof mechanisms for
- eliminating the risk of long lived aliases to temporaries, I think
- warnings are the only practical answer. But I must admit, it's not a
- very good answer. It's just better than silence.
-
-
-
- --
- Robert Martin Training courses offered in:
- R. C. M. Consulting Object Oriented Analysis
- 2080 Cranbrook Rd. Object Oriented Design
- Green Oaks, Il 60048 (708) 918-1004 C++
-