home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!igor!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Newsgroups: comp.lang.c++
- Subject: Re: Destruction of temporaries
- Message-ID: <rmartin.715101472@thor>
- Date: 29 Aug 92 15:17:52 GMT
- References: <MCGRANT.92Aug26232410@rascals.stanford.edu> <23563@alice.att.com> <rmartin.715004480@thor> <23583@alice.att.com>
- Sender: news@Rational.COM
- Lines: 55
-
- ark@alice.att.com (Andrew Koenig) writes:
-
- |In article <rmartin.715004480@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
-
- |> It is in these cases where I would be perfectly happy if the compiler
- |> issued a warning, or even an error.
-
- |Which cases? I don't know how to write a compiler smart enough to
- |distinguish the innocent cases from the guilty ones. Surely you're
- |not suggesting a warning every time you call a function that returns
- |a pointer!
- |--
-
- No, I want a warning every time a temporary gets converted into a
- pointer.
-
- In your example: Given String::operator char*();
- and String String::operator+(const String&); :
-
- String a,b;
- char* c = a+b;
-
- An implicit conversion to char* takes place on a temporary. A warning
- should be possible.
-
- Clearly there are cases where the compiler could be thwarted:
-
- String a,b,s;
- char* c = <some_condition> ? a+b : s;
-
- A simplistic compiler might not be able to see this, but it is
- detectable.
-
-
- 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.
-
- What have I forgotten? Do temporaries present dangers for any context
- in which they are not converted to pointers or references? Are there
- any such contexts where the operand of such a conversion cannot be
- determined to be a temporary?
-
- --
- 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++
-